diff options
author | Owen Lin <owenlin@google.com> | 2011-01-18 04:13:13 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-01-18 04:13:13 -0800 |
commit | 4b26247e8b45850afc78e414a7007266dbdc5d18 (patch) | |
tree | d906faef007f6060d25e2de55828924149dd8454 /graphics | |
parent | f46013b67219b0b2e95fcebb0e51e9816ab0ce94 (diff) | |
parent | a9d0d47076ecf2d1739bb3534abc9deead8ebebd (diff) | |
download | frameworks_base-4b26247e8b45850afc78e414a7007266dbdc5d18.zip frameworks_base-4b26247e8b45850afc78e414a7007266dbdc5d18.tar.gz frameworks_base-4b26247e8b45850afc78e414a7007266dbdc5d18.tar.bz2 |
Merge "Change to stream decoding mode if the file descriptor cannot support seek." into honeycomb
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/BitmapFactory.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index dd6bf19..cffee5f 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -564,11 +564,22 @@ public class BitmapFactory { * @return the decoded bitmap, or null */ public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) { - Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts); - if (bm == null && opts != null && opts.inBitmap != null) { - throw new IllegalArgumentException("Problem decoding into existing bitmap"); + if (nativeIsSeekable(fd)) { + Bitmap bm = nativeDecodeFileDescriptor(fd, outPadding, opts); + if (bm == null && opts != null && opts.inBitmap != null) { + throw new IllegalArgumentException("Problem decoding into existing bitmap"); + } + return finishDecode(bm, outPadding, opts); + } else { + FileInputStream fis = new FileInputStream(fd); + try { + return decodeStream(fis, outPadding, opts); + } finally { + try { + fis.close(); + } catch (Throwable t) {/* ignore */} + } } - return finishDecode(bm, outPadding, opts); } /** @@ -615,4 +626,5 @@ public class BitmapFactory { private static native Bitmap nativeDecodeByteArray(byte[] data, int offset, int length, Options opts); private static native byte[] nativeScaleNinePatch(byte[] chunk, float scale, Rect pad); + private static native boolean nativeIsSeekable(FileDescriptor fd); } |