summaryrefslogtreecommitdiffstats
path: root/graphics/java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/BitmapFactory.java20
1 files changed, 16 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java
index 8309f7a..3f76a10 100644
--- a/graphics/java/android/graphics/BitmapFactory.java
+++ b/graphics/java/android/graphics/BitmapFactory.java
@@ -556,11 +556,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);
}
/**
@@ -607,4 +618,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);
}