Search in sources :

Example 1 with BitmapCreateFlags

use of android.graphics.Bitmap_Delegate.BitmapCreateFlags in project android_frameworks_base by crdroidandroid.

the class BitmapFactory_Delegate method nativeDecodeStream.

// ------ Native Delegates ------
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, @Nullable Rect padding, @Nullable Options opts) {
    Bitmap bm = null;
    Density density = Density.MEDIUM;
    Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
        if (opts.inPremultiplied) {
            bitmapCreateFlags.add(BitmapCreateFlags.PREMULTIPLIED);
        }
        opts.inScaled = false;
    }
    try {
        if (is instanceof NinePatchInputStream) {
            NinePatchInputStream npis = (NinePatchInputStream) is;
            npis.disableFakeMarkSupport();
            // load the bitmap as a nine patch
            com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
            false);
            // get the bitmap and chunk objects.
            bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), bitmapCreateFlags, density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            if (padding != null) {
                // read the padding
                int[] paddingArray = chunk.getPadding();
                padding.left = paddingArray[0];
                padding.top = paddingArray[1];
                padding.right = paddingArray[2];
                padding.bottom = paddingArray[3];
            }
        } else {
            // load the bitmap directly.
            bm = Bitmap_Delegate.createBitmap(is, bitmapCreateFlags, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) BitmapCreateFlags(android.graphics.Bitmap_Delegate.BitmapCreateFlags) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 2 with BitmapCreateFlags

use of android.graphics.Bitmap_Delegate.BitmapCreateFlags in project platform_frameworks_base by android.

the class BitmapFactory_Delegate method nativeDecodeStream.

// ------ Native Delegates ------
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, @Nullable Rect padding, @Nullable Options opts) {
    Bitmap bm = null;
    Density density = Density.MEDIUM;
    Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
        if (opts.inPremultiplied) {
            bitmapCreateFlags.add(BitmapCreateFlags.PREMULTIPLIED);
        }
        opts.inScaled = false;
    }
    try {
        if (is instanceof NinePatchInputStream) {
            NinePatchInputStream npis = (NinePatchInputStream) is;
            npis.disableFakeMarkSupport();
            // load the bitmap as a nine patch
            com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
            false);
            // get the bitmap and chunk objects.
            bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), bitmapCreateFlags, density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            if (padding != null) {
                // read the padding
                int[] paddingArray = chunk.getPadding();
                padding.left = paddingArray[0];
                padding.top = paddingArray[1];
                padding.right = paddingArray[2];
                padding.bottom = paddingArray[3];
            }
        } else {
            // load the bitmap directly.
            bm = Bitmap_Delegate.createBitmap(is, bitmapCreateFlags, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) BitmapCreateFlags(android.graphics.Bitmap_Delegate.BitmapCreateFlags) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 3 with BitmapCreateFlags

use of android.graphics.Bitmap_Delegate.BitmapCreateFlags in project android_frameworks_base by DirtyUnicorns.

the class BitmapFactory_Delegate method nativeDecodeStream.

// ------ Native Delegates ------
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, @Nullable Rect padding, @Nullable Options opts) {
    Bitmap bm = null;
    Density density = Density.MEDIUM;
    Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
        if (opts.inPremultiplied) {
            bitmapCreateFlags.add(BitmapCreateFlags.PREMULTIPLIED);
        }
        opts.inScaled = false;
    }
    try {
        if (is instanceof NinePatchInputStream) {
            NinePatchInputStream npis = (NinePatchInputStream) is;
            npis.disableFakeMarkSupport();
            // load the bitmap as a nine patch
            com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
            false);
            // get the bitmap and chunk objects.
            bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), bitmapCreateFlags, density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            if (padding != null) {
                // read the padding
                int[] paddingArray = chunk.getPadding();
                padding.left = paddingArray[0];
                padding.top = paddingArray[1];
                padding.right = paddingArray[2];
                padding.bottom = paddingArray[3];
            }
        } else {
            // load the bitmap directly.
            bm = Bitmap_Delegate.createBitmap(is, bitmapCreateFlags, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) BitmapCreateFlags(android.graphics.Bitmap_Delegate.BitmapCreateFlags) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 4 with BitmapCreateFlags

use of android.graphics.Bitmap_Delegate.BitmapCreateFlags in project android_frameworks_base by ResurrectionRemix.

the class BitmapFactory_Delegate method nativeDecodeStream.

// ------ Native Delegates ------
@LayoutlibDelegate
static /*package*/
Bitmap nativeDecodeStream(InputStream is, byte[] storage, @Nullable Rect padding, @Nullable Options opts) {
    Bitmap bm = null;
    Density density = Density.MEDIUM;
    Set<BitmapCreateFlags> bitmapCreateFlags = EnumSet.of(BitmapCreateFlags.MUTABLE);
    if (opts != null) {
        density = Density.getEnum(opts.inDensity);
        if (opts.inPremultiplied) {
            bitmapCreateFlags.add(BitmapCreateFlags.PREMULTIPLIED);
        }
        opts.inScaled = false;
    }
    try {
        if (is instanceof NinePatchInputStream) {
            NinePatchInputStream npis = (NinePatchInputStream) is;
            npis.disableFakeMarkSupport();
            // load the bitmap as a nine patch
            com.android.ninepatch.NinePatch ninePatch = com.android.ninepatch.NinePatch.load(npis, true, /*is9Patch*/
            false);
            // get the bitmap and chunk objects.
            bm = Bitmap_Delegate.createBitmap(ninePatch.getImage(), bitmapCreateFlags, density);
            NinePatchChunk chunk = ninePatch.getChunk();
            // put the chunk in the bitmap
            bm.setNinePatchChunk(NinePatch_Delegate.serialize(chunk));
            if (padding != null) {
                // read the padding
                int[] paddingArray = chunk.getPadding();
                padding.left = paddingArray[0];
                padding.top = paddingArray[1];
                padding.right = paddingArray[2];
                padding.bottom = paddingArray[3];
            }
        } else {
            // load the bitmap directly.
            bm = Bitmap_Delegate.createBitmap(is, bitmapCreateFlags, density);
        }
    } catch (IOException e) {
        Bridge.getLog().error(null, "Failed to load image", e, null);
    }
    return bm;
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) NinePatchChunk(com.android.ninepatch.NinePatchChunk) IOException(java.io.IOException) Density(com.android.resources.Density) BitmapCreateFlags(android.graphics.Bitmap_Delegate.BitmapCreateFlags) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

BitmapCreateFlags (android.graphics.Bitmap_Delegate.BitmapCreateFlags)4 NinePatchInputStream (com.android.layoutlib.bridge.util.NinePatchInputStream)4 NinePatchChunk (com.android.ninepatch.NinePatchChunk)4 Density (com.android.resources.Density)4 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)4 IOException (java.io.IOException)4