diff --git a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java index b532ffe..26b7cea 100644 --- a/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java +++ b/simplecropview/src/main/java/com/isseiaoki/simplecropview/CropImageView.java @@ -1011,7 +1011,7 @@ public Bitmap getCroppedBitmap() { Bitmap source = getBitmap(); if (source == null) return null; - int x, y, w, h; + int x, y, w, h, sw, sh; float l = (mFrameRect.left / mScale); float t = (mFrameRect.top / mScale); float r = (mFrameRect.right / mScale); @@ -1021,6 +1021,15 @@ public Bitmap getCroppedBitmap() { w = Math.round(r - l); h = Math.round(b - t); + if(w > source.getWidth()){ + w = source.getWidth(); + x = 0; + } + if(h > source.getHeight()){ + h = source.getHeight(); + y = 0; + } + Bitmap cropped = Bitmap.createBitmap(source, x, y, w, h, null, false); if (mCropMode != CropMode.CIRCLE) return cropped; return getCircularBitmap(cropped); @@ -1048,6 +1057,15 @@ public Bitmap getRectBitmap() { w = Math.round(r - l); h = Math.round(b - t); + if(w > source.getWidth()){ + w = source.getWidth(); + x = 0; + } + if(h > source.getHeight()){ + h = source.getHeight(); + y = 0; + } + return Bitmap.createBitmap(source, x, y, w, h, null, false); }