/** * Fit croper to preview size. * * @param ratio Preview's ratio. */ private void fitCropImageView(float ratio) { final Bitmap bitmap = Bitmap.createBitmap( mTextureView.getMeasuredWidth(), (int) (mTextureView.getMeasuredWidth() * ratio), Bitmap.Config.ARGB_8888); mCropper.setImageBitmap(bitmap); }
/** * Rotates image by the specified number of degrees clockwise. Cycles from 0 to 360 degrees. * * @param degrees Integer specifying the number of degrees to rotate. */ public void rotateImage(int degrees) { Matrix matrix = new Matrix(); matrix.postRotate(degrees); mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true); setImageBitmap(mBitmap); mDegreesRotated += degrees; mDegreesRotated = mDegreesRotated % 360; }
/** * Sets a Drawable as the content of the CropImageView. * * @param path the file path to set */ public void setImageResource(String path) { if (path != null) { Bitmap bitmap = BitmapFactory.decodeFile(path); setImageBitmap(bitmap); } }