use of org.robolectric.shadows.ImageUtil.RobolectricBufferedImage in project robolectric by robolectric.
the class ShadowBitmapFactory method decodeFileDescriptor.
@SuppressWarnings({ "ObjectToString", "Var" })
@Implementation
protected static Bitmap decodeFileDescriptor(FileDescriptor fd, Rect outPadding, BitmapFactory.Options opts) {
RobolectricBufferedImage image = null;
// If a real FileDescriptor is used, attempt to get the image size.
if (fd != null && fd.valid()) {
try (FileInputStream fileInputStream = new FileInputStream(fd);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) {
image = getImageFromStream(bufferedInputStream);
} catch (IOException e) {
Logger.warn("Error getting size of bitmap file", e);
}
}
if (!allowInvalidImageData && image == null) {
if (opts != null) {
opts.outWidth = -1;
opts.outHeight = -1;
}
return null;
}
Bitmap bitmap = create("fd:" + fd, outPadding, opts, null, image);
ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
shadowBitmap.createdFromFileDescriptor = fd;
return bitmap;
}
Aggregations