Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); canvas.drawBitmap(source, matrix, new Paint());
Matrix matrix = new Matrix(); matrix.setRotate(angle, imageCenterX, imageCenterY); yourCanvas.drawBitmap(yourBitmap, matrix, null);
break; case ExifInterface.ORIENTATION_ROTATE_180: matrix.setRotate(180); break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: matrix.setRotate(180); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_TRANSPOSE: matrix.setRotate(90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_90: matrix.setRotate(90); break; case ExifInterface.ORIENTATION_TRANSVERSE: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case ExifInterface.ORIENTATION_ROTATE_270: matrix.setRotate(-90); break; default:
public BitmapDrawable rotateDrawable(float angle) { Bitmap arrowBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.map_pin); // Create blank bitmap of equal size Bitmap canvasBitmap = arrowBitmap.copy(Bitmap.Config.ARGB_8888, true); canvasBitmap.eraseColor(0x00000000); // Create canvas Canvas canvas = new Canvas(canvasBitmap); // Create rotation matrix Matrix rotateMatrix = new Matrix(); rotateMatrix.setRotate(angle, canvas.getWidth()/2, canvas.getHeight()/2); // Draw bitmap onto canvas using matrix canvas.drawBitmap(arrowBitmap, rotateMatrix, null); return new BitmapDrawable(canvasBitmap); }
BitmapFactory.Options bounds = new BitmapFactory.Options(); bounds.inJustDecodeBounds = true; BitmapFactory.decodeFile(file, bounds); BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm = BitmapFactory.decodeFile(file, opts); ExifInterface exif = new ExifInterface(file); String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION); int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL; int rotationAngle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90; if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180; if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270; Matrix matrix = new Matrix(); matrix.setRotate(rotationAngle, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0, bounds.outWidth, bounds.outHeight, matrix, true);
break; case 3: matrix.setRotate(180); break; case 4: matrix.setRotate(180); matrix.postScale(-1, 1); break; case 5: matrix.setRotate(90); matrix.postScale(-1, 1); break; case 6: matrix.setRotate(90); break; case 7: matrix.setRotate(-90); matrix.postScale(-1, 1); break; case 8: matrix.setRotate(-90); break; default:
mtx.setRotate(degree);
Matrix matrix = new Matrix(); matrix.setRotate(degrees); Bitmap bmpBowRotated = Bitmap.createBitmap(bmpBow, 0, 0, bmpBow.getWidth(),getHeight(), matrix, false);
public static Bitmap rotate(Bitmap b, int degrees) { if (degrees != 0 && b != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2); try { Bitmap b2 = Bitmap.createBitmap( b, 0, 0, b.getWidth(), b.getHeight(), m, true); if (b != b2) { b.recycle(); b = b2; } } catch (OutOfMemoryError ex) { throw ex; } } return b; }
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); canvas.drawBitmap(source, matrix, new Paint());
Bitmap baseFrame; Bitmap rotatedFrame[]=new Bitmap[360/10]; ... Matrix rotationMatrix=new Matrix(); rotationMatrix.setRotate(n*10); rotatedFrame[n]=Bitmap.createBitmap(baseFrame,0,0, baseFrame.getWidth(), baseFrame.getHeight(), rotationMatrix, false);
@Override public void onClick(View view) { Matrix matrix = new Matrix(); matrix.setRotate(10); Bitmap copy = image; Bitmap newImage = Bitmap.createBitmap(copy, 0, 0, image.getWidth(), image.getHeight(), matrix, true); setNewImage(newImage); }
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); canvas.drawBitmap(source, matrix, new Paint());
Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); RectF rectF = new RectF(0, 0, source.getWidth(), source.getHeight()); matrix.mapRect(rectF); Bitmap targetBitmap = Bitmap.createBitmap(rectF.width(), rectF.height(), config); Canvas canvas = new Canvas(targetBitmap); canvas.drawBitmap(source, matrix, new Paint());
Matrix minMatrix = new Matrix(); //height and width are set earlier. Bitmap minBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas minCanvas = new Canvas(minBitmap); int minwidth = bitmapMin.getWidth(); int minheight = bitmapMin.getHeight(); int centrex = minwidth/2; int centrey = minheight/2; minMatrix.setRotate(mindegrees, centrex, centrey); Bitmap newmin = Bitmap.createBitmap(minBitmap, 0, 0, (int) minwidth, (int) minheight, minMatrix, true); minCanvas.drawBitmap(newmin, (centrex - newmin.getWidth()/2), (centrey - newmin.getHeight()/2), null); minCanvas.setBitmap(minBitmap);
public static Bitmap RotateBitmap(Bitmap source, float angle) { Matrix matrix = new Matrix(); matrix.setRotate(90, 0, 0); matrix.postTranslate(source.getHeight(), 0); // matrix.postRotate(angle); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); } Utility.tempBitmap = RotateBitmap(Utility.tempBitmap, -90);
Bitmap original = ((BitmapDrawable) yourImageView.getDrawable()).getBitmap(); Matrix matrix = new Matrix(); matrix.setRotate(degrees); matrix.postScale(scale, scale); Bitmap result = Bitmap.createBitmap(original, 0, 0, original.getWidth(), original.getHeight(), matrix, true);
scaledImage = Bitmap.createBitmap (croppedWidth, croppedHeight, Bitmap.Config.ARGB_8888); Canvas offscreenCanvas = new Canvas (scaledImage); Matrix matrix = new Matrix(); matrix.setRotate (rotations, centreX, centreY); matrix.postScale(scaleX, scaleY); offscreenCanvas.setMatrix (matrix); offscreenCanvas.drawBitmap (pickedImage, 0, 0, new Paint(Paint.DITHER_FLAG));
Matrix m = new Matrix(); // point is the point about which to rotate. m.setRotate(degrees, point.x, point.y); m.mapRect(r);
Matrix matrix = new Matrix(); matrix.setRotate(m.getRotation(), midx, midy); matrix.postScale(m.getSize(), m.getSize(), midx, midy); Matrix inverse = new Matrix(); matrix.invert(inverse); pts[0] = x; pts[1] = y; inverse.mapPoints(pts); if(pts[1] >= top && pts[1] <= bottom && pts[0] >= left && pts[0] <= right) { return i; }