Search in sources :

Example 6 with RobolectricBufferedImage

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;
}
Also used : Bitmap(android.graphics.Bitmap) RobolectricBufferedImage(org.robolectric.shadows.ImageUtil.RobolectricBufferedImage) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Bitmap (android.graphics.Bitmap)6 RobolectricBufferedImage (org.robolectric.shadows.ImageUtil.RobolectricBufferedImage)6 Implementation (org.robolectric.annotation.Implementation)5 BufferedInputStream (java.io.BufferedInputStream)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 AssetInputStream (android.content.res.AssetManager.AssetInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Config (android.graphics.Bitmap.Config)1 BitmapFactory (android.graphics.BitmapFactory)1 Point (android.graphics.Point)1 TypedValue (android.util.TypedValue)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 InputStream (java.io.InputStream)1 NamedStream (org.robolectric.util.NamedStream)1