From 53106863f168e5a5404b70781fedc74090c09a1f Mon Sep 17 00:00:00 2001 From: Jay Wang Date: Tue, 13 Sep 2016 17:02:21 -0700 Subject: SnapdragonGallery: check for valid background before saving Check to make sure previously selected background is valid before attempting to flatten and save. If background does not exist, save without background. CRs-Fixed: 1062655 Change-Id: I1a3553d6d93d949b6884d3f3301d6f1f53348393 --- .../gallery3d/filtershow/tools/SaveImage.java | 53 ++++++++++++---------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/com/android/gallery3d/filtershow/tools/SaveImage.java b/src/com/android/gallery3d/filtershow/tools/SaveImage.java index 87492a335..073aca4cd 100644 --- a/src/com/android/gallery3d/filtershow/tools/SaveImage.java +++ b/src/com/android/gallery3d/filtershow/tools/SaveImage.java @@ -368,6 +368,11 @@ public class SaveImage { if(hasFusion) { previewBmp = flattenFusion(Uri.parse(fusionRep.getUnderlay()), mPreviewImage, Math.max(mPreviewImage.getWidth(), mPreviewImage.getHeight()), 0); + // If we fail to flatten, save original image + if(previewBmp == null) { + previewBmp = mPreviewImage; + hasFusion = false; + } } else { previewBmp = mPreviewImage; } @@ -447,9 +452,10 @@ public class SaveImage { if(hasFusion) { Bitmap underlay = flattenFusion( Uri.parse(fusionRep.getUnderlay()), bitmap, 0, sampleSize); - - bitmap.recycle(); - bitmap = underlay; + if(underlay != null) { + bitmap.recycle(); + bitmap = underlay; + } } updateProgress(); @@ -820,26 +826,27 @@ public class SaveImage { underlay = ImageLoader.loadBitmapWithBackouts(mContext, underlayUri, sampleSize); } - RectF destRect = new RectF(); - Rect imageBounds = MasterImage.getImage().getImageBounds(); - Rect underlayBounds = MasterImage.getImage().getFusionBounds(); - float underlayScaleFactor = (float)underlay.getWidth() - / (float)underlayBounds.width(); - - destRect.left = (imageBounds.left - underlayBounds.left) * underlayScaleFactor; - destRect.right = (imageBounds.right - underlayBounds.left) * underlayScaleFactor; - destRect.top = (imageBounds.top - underlayBounds.top) * underlayScaleFactor; - destRect.bottom = (imageBounds.bottom - underlayBounds.top) * underlayScaleFactor; - - Canvas canvas = new Canvas(underlay); - Paint paint = new Paint(); - paint.reset(); - paint.setAntiAlias(true); - paint.setFilterBitmap(true); - paint.setDither(true); - - canvas.drawBitmap(bitmap, null, destRect, paint); - + if(underlay != null) { + RectF destRect = new RectF(); + Rect imageBounds = MasterImage.getImage().getImageBounds(); + Rect underlayBounds = MasterImage.getImage().getFusionBounds(); + float underlayScaleFactor = (float)underlay.getWidth() + / (float)underlayBounds.width(); + + destRect.left = (imageBounds.left - underlayBounds.left) * underlayScaleFactor; + destRect.right = (imageBounds.right - underlayBounds.left) * underlayScaleFactor; + destRect.top = (imageBounds.top - underlayBounds.top) * underlayScaleFactor; + destRect.bottom = (imageBounds.bottom - underlayBounds.top) * underlayScaleFactor; + + Canvas canvas = new Canvas(underlay); + Paint paint = new Paint(); + paint.reset(); + paint.setAntiAlias(true); + paint.setFilterBitmap(true); + paint.setDither(true); + + canvas.drawBitmap(bitmap, null, destRect, paint); + } return underlay; } } -- cgit v1.2.3