naver / android-imagecropview

android image crop library
Apache License 2.0
254 stars 55 forks source link

getCroppedImage returns different size for smaller bitmaps #4

Closed rafalzawadzki closed 9 years ago

rafalzawadzki commented 9 years ago

When bitmap size is greater than view's dimensions, the returned bitmap is cropped correctly. If ImageCropView has bitmap with size smaller than view's size, the bitmap is scaled up to fit view dimensions, but .getCroppedImage() method returns the unscaled bitmap.

Is there any way to return the bitmap with size as seen in the ImageCropView?

helloyako commented 9 years ago

If you want, you can create scaled up bitmap after getCroppedIamge.

    Bitmap cropBitmap = ImageCropView.getCroppedIamge();
    int width = cropBitmap.getWidth();
    int height = cropBitmap.getHeight();
    int newWidth = 300;
    int newHeight = 300;
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;

    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizeBitmap = Bitmap.createBitmap(cropBitmap, 0, 0, width, height, matrix, false);