Loading packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java +33 −4 Original line number Diff line number Diff line Loading @@ -83,6 +83,12 @@ public class WallpaperCropActivity extends Activity { } } @Override protected void onDestroy(){ super.onDestroy(); mCropView.destroy(); } protected void init() { setContentView(R.layout.wallpaper_cropper); Loading Loading @@ -506,7 +512,13 @@ public class WallpaperCropActivity extends Activity { InputStream is = regenerateInputStream(); if (is != null) { BitmapFactory.Options options = new BitmapFactory.Options(); //inSampleSize - decreases height/width of image to be loaded by a factor of 4 //inPurgeable - pixels can be purged if system needs to reclaim memory //inInputShareable - bitmap keeps a shallow reference to input options.inJustDecodeBounds = true; options.inSampleSize = 4; options.inInputShareable = true; options.inPurgeable = true; BitmapFactory.decodeStream(is, null, options); Utils.closeSilently(is); if (options.outWidth != 0 && options.outHeight != 0) { Loading Loading @@ -584,7 +596,9 @@ public class WallpaperCropActivity extends Activity { } // See how much we're reducing the size of the image int scaleDownSampleSize = Math.max(1, Math.min(roundedTrueCrop.width() / mOutWidth, //This is a hard coded optimization //No apparent degradation in quality but major reduction in amt of memory consumed. int scaleDownSampleSize = Math.max(4, Math.min(roundedTrueCrop.width() / mOutWidth, roundedTrueCrop.height() / mOutHeight)); // Attempt to open a region decoder BitmapRegionDecoder decoder = null; Loading @@ -609,6 +623,8 @@ public class WallpaperCropActivity extends Activity { if (decoder != null) { // Do region decoding to get crop bitmap BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true; if (scaleDownSampleSize > 1) { options.inSampleSize = scaleDownSampleSize; } Loading @@ -620,8 +636,11 @@ public class WallpaperCropActivity extends Activity { // BitmapRegionDecoder has failed, try to crop in-memory is = regenerateInputStream(); Bitmap fullSize = null; if (is != null) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true; if (scaleDownSampleSize > 1) { options.inSampleSize = scaleDownSampleSize; } Loading @@ -643,9 +662,10 @@ public class WallpaperCropActivity extends Activity { roundedTrueCrop.right, (int) mCropBounds.bottom); } crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, roundedTrueCrop.top, roundedTrueCrop.width(), roundedTrueCrop.height()); crop = Bitmap.createScaledBitmap(fullSize, roundedTrueCrop.width(), roundedTrueCrop.height(), false); fullSize.recycle(); fullSize = null; } } Loading Loading @@ -695,6 +715,10 @@ public class WallpaperCropActivity extends Activity { Paint p = new Paint(); p.setFilterBitmap(true); c.drawBitmap(crop, m, p); if (crop != null) { crop.recycle(); crop = null; } crop = tmp; } } Loading Loading @@ -727,6 +751,11 @@ public class WallpaperCropActivity extends Activity { Log.w(LOGTAG, "cannot compress bitmap"); failure = true; } try { tmpOut.close(); } catch (IOException e) { Log.w(LOGTAG, "Error closing ByteArray"); } } return !failure; // True if any of the operations failed } Loading Loading
packages/WallpaperCropper/src/com/android/wallpapercropper/WallpaperCropActivity.java +33 −4 Original line number Diff line number Diff line Loading @@ -83,6 +83,12 @@ public class WallpaperCropActivity extends Activity { } } @Override protected void onDestroy(){ super.onDestroy(); mCropView.destroy(); } protected void init() { setContentView(R.layout.wallpaper_cropper); Loading Loading @@ -506,7 +512,13 @@ public class WallpaperCropActivity extends Activity { InputStream is = regenerateInputStream(); if (is != null) { BitmapFactory.Options options = new BitmapFactory.Options(); //inSampleSize - decreases height/width of image to be loaded by a factor of 4 //inPurgeable - pixels can be purged if system needs to reclaim memory //inInputShareable - bitmap keeps a shallow reference to input options.inJustDecodeBounds = true; options.inSampleSize = 4; options.inInputShareable = true; options.inPurgeable = true; BitmapFactory.decodeStream(is, null, options); Utils.closeSilently(is); if (options.outWidth != 0 && options.outHeight != 0) { Loading Loading @@ -584,7 +596,9 @@ public class WallpaperCropActivity extends Activity { } // See how much we're reducing the size of the image int scaleDownSampleSize = Math.max(1, Math.min(roundedTrueCrop.width() / mOutWidth, //This is a hard coded optimization //No apparent degradation in quality but major reduction in amt of memory consumed. int scaleDownSampleSize = Math.max(4, Math.min(roundedTrueCrop.width() / mOutWidth, roundedTrueCrop.height() / mOutHeight)); // Attempt to open a region decoder BitmapRegionDecoder decoder = null; Loading @@ -609,6 +623,8 @@ public class WallpaperCropActivity extends Activity { if (decoder != null) { // Do region decoding to get crop bitmap BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true; if (scaleDownSampleSize > 1) { options.inSampleSize = scaleDownSampleSize; } Loading @@ -620,8 +636,11 @@ public class WallpaperCropActivity extends Activity { // BitmapRegionDecoder has failed, try to crop in-memory is = regenerateInputStream(); Bitmap fullSize = null; if (is != null) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true; if (scaleDownSampleSize > 1) { options.inSampleSize = scaleDownSampleSize; } Loading @@ -643,9 +662,10 @@ public class WallpaperCropActivity extends Activity { roundedTrueCrop.right, (int) mCropBounds.bottom); } crop = Bitmap.createBitmap(fullSize, roundedTrueCrop.left, roundedTrueCrop.top, roundedTrueCrop.width(), roundedTrueCrop.height()); crop = Bitmap.createScaledBitmap(fullSize, roundedTrueCrop.width(), roundedTrueCrop.height(), false); fullSize.recycle(); fullSize = null; } } Loading Loading @@ -695,6 +715,10 @@ public class WallpaperCropActivity extends Activity { Paint p = new Paint(); p.setFilterBitmap(true); c.drawBitmap(crop, m, p); if (crop != null) { crop.recycle(); crop = null; } crop = tmp; } } Loading Loading @@ -727,6 +751,11 @@ public class WallpaperCropActivity extends Activity { Log.w(LOGTAG, "cannot compress bitmap"); failure = true; } try { tmpOut.close(); } catch (IOException e) { Log.w(LOGTAG, "Error closing ByteArray"); } } return !failure; // True if any of the operations failed } Loading