List of usage examples for android.graphics Matrix postTranslate
public boolean postTranslate(float dx, float dy)
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();/*from ww w . ja v a 2 s .co m*/ targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(bm1); canvas.drawBitmap(bm, m, paint); bm.recycle(); bm = null; return bm1; }
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();/*from w w w .j a v a 2 s . c o m*/ targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap temp = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(temp); canvas.drawBitmap(bm, m, paint); return temp; }
From source file:Main.java
private static Bitmap decodeExifBitmap(File file, Bitmap src) { try {/*from w ww . ja v a 2s . c o m*/ // Try to load the bitmap as a bitmap file ExifInterface exif = new ExifInterface(file.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == ExifInterface.ORIENTATION_NORMAL) { return src; } Matrix matrix = new Matrix(); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { matrix.postRotate(90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { matrix.postRotate(180); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { matrix.postRotate(270); } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { matrix.setScale(-1, 1); matrix.postTranslate(src.getWidth(), 0); } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { matrix.setScale(1, -1); matrix.postTranslate(0, src.getHeight()); } // Rotate the bitmap return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (IOException e) { // Ignore } return src; }
From source file:com.ruesga.rview.misc.BitmapUtils.java
private static Bitmap decodeExifBitmap(File file, Bitmap src) { if (src != null) { try {//from w ww .ja v a 2 s . c om // Try to load the bitmap as a bitmap file ExifInterface exif = new ExifInterface(file.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == ExifInterface.ORIENTATION_NORMAL) { return src; } Matrix matrix = new Matrix(); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: matrix.postRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.postRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.postRotate(270); break; case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: matrix.setScale(-1, 1); matrix.postTranslate(src.getWidth(), 0); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setScale(1, -1); matrix.postTranslate(0, src.getHeight()); break; } // Rotate the bitmap return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (IOException e) { // Ignore } } return src; }
From source file:com.f2prateek.dfg.core.GenerateFrameService.java
@Override public void startingImage(Bitmap screenshot) { // Create the large notification icon int imageWidth = screenshot.getWidth(); int imageHeight = screenshot.getHeight(); int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight; // Check for if config is null, http://crashes.to/s/dd0857c8648 Bitmap preview = Bitmap.createBitmap(shortSide, shortSide, screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig()); Canvas c = new Canvas(preview); Paint paint = new Paint(); ColorMatrix desat = new ColorMatrix(); desat.setSaturation(0.25f);/*w w w. j a v a 2s. c o m*/ paint.setColorFilter(new ColorMatrixColorFilter(desat)); Matrix matrix = new Matrix(); matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2); c.drawBitmap(screenshot, matrix, paint); c.drawColor(0x40FFFFFF); Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true); Intent nullIntent = new Intent(this, MainActivity.class); nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(this) .setTicker(resources.getString(R.string.screenshot_saving_ticker)) .setContentTitle(resources.getString(R.string.screenshot_saving_title)) .setSmallIcon(R.drawable.ic_stat_app_notification) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview)) .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0)) .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon); Notification n = notificationBuilder.build(); n.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(DFG_NOTIFICATION_ID, n); }
From source file:com.sspai.dkjt.service.GenerateFrameService.java
@Override public void startingImage(Bitmap screenshot) { // Create the large notification icon int imageWidth = screenshot.getWidth(); int imageHeight = screenshot.getHeight(); int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight; // Check for if config is null, http://crashes.to/s/dd0857c8648 Bitmap preview = Bitmap.createBitmap(shortSide, shortSide, screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig()); Canvas c = new Canvas(preview); Paint paint = new Paint(); ColorMatrix desat = new ColorMatrix(); desat.setSaturation(0.25f);/*from w ww . java 2 s . c om*/ paint.setColorFilter(new ColorMatrixColorFilter(desat)); Matrix matrix = new Matrix(); matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2); c.drawBitmap(screenshot, matrix, paint); c.drawColor(0x40FFFFFF); Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true); Intent nullIntent = new Intent(this, MainActivity.class); nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(this) .setTicker(resources.getString(R.string.screenshot_saving_ticker)) .setContentTitle(resources.getString(R.string.screenshot_saving_title)) .setSmallIcon(R.drawable.ic_actionbar_logo) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview)) .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0)) .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon); Notification n = notificationBuilder.build(); n.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(DFG_NOTIFICATION_ID, n); }
From source file:com.frapim.windwatch.Notifier.java
private Path getArrowPath(float degrees) { Path path = new Path(); int leftX = (mBigIconSize / 2) - (mArrowWidth / 2); int leftHeadX = leftX - mArrowWidth; int rightX = (mBigIconSize / 2) + (mArrowWidth / 2); int rightHeadX = rightX + mArrowWidth; path.moveTo(leftX, mArrowHeight); // bottom left path.lineTo(leftX, mArrowHeadHeight); // left, arrow head start path.lineTo(leftHeadX, mArrowHeadHeight); // left, arrow head end path.lineTo(mBigIconSize / 2, 0); // top path.lineTo(rightHeadX, mArrowHeadHeight); // right, arrow head end path.lineTo(rightX, mArrowHeadHeight); // right, arrow head start path.lineTo(rightX, mArrowHeight); // bottom right path.lineTo(leftX, mArrowHeight); // bottom left path.close();/*from ww w. ja va 2 s .c o m*/ Matrix translateMatrix = new Matrix(); translateMatrix.postTranslate(0, 30); path.transform(translateMatrix); RectF bounds = new RectF(); path.computeBounds(bounds, true); Matrix rotateMatrix = new Matrix(); rotateMatrix.postRotate(degrees, (bounds.right + bounds.left) / 2, (bounds.bottom + bounds.top) / 2); path.transform(rotateMatrix); return path; }
From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java
static void setBackground(View v, Bitmap bm) { if (bm == null) { v.setBackgroundResource(0);/*from w w w. ja v a2 s . c o m*/ return; } int vwidth = v.getWidth(); int vheight = v.getHeight(); int bwidth = bm.getWidth(); int bheight = bm.getHeight(); float scalex = (float) vwidth / bwidth; float scaley = (float) vheight / bheight; float scale = Math.max(scalex, scaley) * 1.3f; Bitmap.Config config = Bitmap.Config.ARGB_8888; Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config); Canvas c = new Canvas(bg); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setFilterBitmap(true); ColorMatrix greymatrix = new ColorMatrix(); greymatrix.setSaturation(0); ColorMatrix darkmatrix = new ColorMatrix(); darkmatrix.setScale(.3f, .3f, .3f, 1.0f); greymatrix.postConcat(darkmatrix); ColorFilter filter = new ColorMatrixColorFilter(greymatrix); paint.setColorFilter(filter); Matrix matrix = new Matrix(); matrix.setTranslate(-bwidth / 2, -bheight / 2); // move bitmap center to origin matrix.postRotate(10); matrix.postScale(scale, scale); matrix.postTranslate(vwidth / 2, vheight / 2); // Move bitmap center to view center c.drawBitmap(bm, matrix, paint); v.setBackgroundDrawable(new BitmapDrawable(bg)); }
From source file:com.fractview.ImageViewFragment.java
private void initImageMatrix() { // Set initMatrix + inverse to current view-size float vw = imageView.getWidth(); float vh = imageView.getHeight(); // Right after creation, this view might not // be inside anything and therefore have size 0. if (vw <= 0 && vh <= 0) return; // do nothing. float bw = taskFragment.bitmap().getWidth(); float bh = taskFragment.bitmap().getHeight(); RectF viewRect = new RectF(0f, 0f, vw, vh); RectF bitmapRect;//from ww w .j a va 2s . c o m if (vw > vh) { // if width of view is bigger, match longer side to it bitmapRect = new RectF(0f, 0f, Math.max(bw, bh), Math.min(bw, bh)); } else { bitmapRect = new RectF(0f, 0f, Math.min(bw, bh), Math.max(bw, bh)); } viewToImageMatrix.setRectToRect(bitmapRect, viewRect, viewPolicy); if (vw > vh ^ bw > bh) { // Turn centerImageMatrix by 90 degrees Matrix m = new Matrix(); m.postRotate(90f); m.postTranslate(bh, 0); viewToImageMatrix.preConcat(m); } if (!viewToImageMatrix.invert(inverseViewToImageMatrix)) { throw new IllegalArgumentException("matrix cannot be inverted..."); } imageView.setImageMatrix(viewToImageMatrix); }
From source file:ca.frozen.rpicameraviewer.views.ZoomPanTextureView.java
private void setTransform() { // get the view size int viewWidth = getWidth(); int viewHeight = getHeight(); // scale relative to the center Matrix transform = new Matrix(); transform.postScale(fitZoom.x * zoom, fitZoom.y * zoom, viewWidth / 2, viewHeight / 2); // add the panning if (pan.x != 0 || pan.y != 0) { transform.postTranslate(pan.x, pan.y); }/*from w ww. ja v a2s. c o m*/ // set the transform setTransform(transform); invalidate(); }