Add support to BitmapFactory for decoding a bitmap from a MemoryFile FileDescriptor.
This commit is contained in:
@@ -18,6 +18,7 @@ package android.graphics;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.MemoryFile;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
@@ -435,6 +436,17 @@ public class BitmapFactory {
|
||||
* @return the decoded bitmap, or null
|
||||
*/
|
||||
public static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, Options opts) {
|
||||
try {
|
||||
if (MemoryFile.isMemoryFile(fd)) {
|
||||
int mappedlength = MemoryFile.getMappedSize(fd);
|
||||
MemoryFile file = new MemoryFile(fd, mappedlength, "r");
|
||||
InputStream is = file.getInputStream();
|
||||
return decodeStream(is, outPadding, opts);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
// invalid filedescriptor, no need to call nativeDecodeFileDescriptor()
|
||||
return null;
|
||||
}
|
||||
return nativeDecodeFileDescriptor(fd, outPadding, opts);
|
||||
}
|
||||
|
||||
@@ -447,7 +459,7 @@ public class BitmapFactory {
|
||||
* @return the decoded bitmap, or null
|
||||
*/
|
||||
public static Bitmap decodeFileDescriptor(FileDescriptor fd) {
|
||||
return nativeDecodeFileDescriptor(fd, null, null);
|
||||
return decodeFileDescriptor(fd, null, null);
|
||||
}
|
||||
|
||||
private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,
|
||||
|
||||
Reference in New Issue
Block a user