diff options
author | Chih-Chung Chang <chihchung@google.com> | 2009-09-22 16:47:43 -0700 |
---|---|---|
committer | Chih-Chung Chang <chihchung@google.com> | 2009-09-22 19:35:46 -0700 |
commit | cd972b0cd67d7a45084d9757ebd49b8f22989edd (patch) | |
tree | 87343dd93fa06dbb55a46c023cbf18ef10c6ead0 /src/com/android/camera/Util.java | |
parent | 5c3949ab2989a1a7f30f4abd76a28250892f66b5 (diff) | |
download | LegacyCamera-cd972b0cd67d7a45084d9757ebd49b8f22989edd.zip LegacyCamera-cd972b0cd67d7a45084d9757ebd49b8f22989edd.tar.gz LegacyCamera-cd972b0cd67d7a45084d9757ebd49b8f22989edd.tar.bz2 |
Fix 2129498: add a MaxNumOfPixels parameter for client to specify the captured picture size.
Diffstat (limited to 'src/com/android/camera/Util.java')
-rw-r--r-- | src/com/android/camera/Util.java | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index 659a99e..a417e32 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -386,14 +386,12 @@ public class Util { public static Bitmap makeBitmap(int minSideLength, int maxNumOfPixels, Uri uri, ContentResolver cr, ParcelFileDescriptor pfd, BitmapFactory.Options options) { - Bitmap b = null; try { if (pfd == null) pfd = makeInputStream(uri, cr); if (pfd == null) return null; if (options == null) options = new BitmapFactory.Options(); FileDescriptor fd = pfd.getFileDescriptor(); - options.inSampleSize = 1; options.inJustDecodeBounds = true; BitmapManager.instance().decodeFileDescriptor(fd, options); if (options.mCancel || options.outWidth == -1 @@ -406,14 +404,37 @@ public class Util { options.inDither = false; options.inPreferredConfig = Bitmap.Config.ARGB_8888; - b = BitmapManager.instance().decodeFileDescriptor(fd, options); + return BitmapManager.instance().decodeFileDescriptor(fd, options); } catch (OutOfMemoryError ex) { Log.e(TAG, "Got oom exception ", ex); return null; } finally { closeSilently(pfd); } - return b; + } + + public static Bitmap makeBitmap(byte[] jpegData, int maxNumOfPixels) { + try { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; + BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, + options); + if (options.mCancel || options.outWidth == -1 + || options.outHeight == -1) { + return null; + } + options.inSampleSize = computeSampleSize( + options, IImage.UNCONSTRAINED, maxNumOfPixels); + options.inJustDecodeBounds = false; + + options.inDither = false; + options.inPreferredConfig = Bitmap.Config.ARGB_8888; + return BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, + options); + } catch (OutOfMemoryError ex) { + Log.e(TAG, "Got oom exception ", ex); + return null; + } } private static ParcelFileDescriptor makeInputStream( |