Example usage for android.graphics BitmapFactory decodeResourceStream

List of usage examples for android.graphics BitmapFactory decodeResourceStream

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResourceStream.

Prototype

@Nullable
public static Bitmap decodeResourceStream(@Nullable Resources res, @Nullable TypedValue value,
        @Nullable InputStream is, @Nullable Rect pad, @Nullable Options opts) 

Source Link

Document

Decode a new Bitmap from an InputStream.

Usage

From source file:Main.java

public static Bitmap getBitmapForDensity(Resources res, int displayDpi, int resId) {
    try {//from   w w w. ja va 2 s  .c om
        TypedValue value = new TypedValue();
        res.getValueForDensity(resId, displayDpi, value, true);
        AssetFileDescriptor fd = res.getAssets().openNonAssetFd(value.assetCookie, value.string.toString());
        Options opt = new Options();
        opt.inTargetDensity = displayDpi;
        Bitmap bitmap = BitmapFactory.decodeResourceStream(res, value, fd.createInputStream(), null, opt);
        bitmap.setDensity(res.getDisplayMetrics().densityDpi);
        fd.close();
        return bitmap;
    } catch (Exception e) {
        return BitmapFactory.decodeResource(res, resId);
    }
}

From source file:Main.java

private static Bitmap getMutableBitmap(Resources res, TypedValue value, InputStream is, Rect pad) {
    return BitmapFactory.decodeResourceStream(res, value, is, pad, getMutableOption());
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Creates and returns a Bitmap from an InputStream.
 * @param stream an InputStream to read bitmap data.
 * @param opts BitmapFactory options// ww  w. ja v a2 s  .  c  o m
 * @return a new bitmap instance.
 * @module.api
 */
public static Bitmap createBitmap(InputStream stream, BitmapFactory.Options opts) {
    Rect pad = new Rect();
    if (opts == null) {
        opts = TiBitmapPool.defaultBitmapOptions();
    }
    Bitmap b = null;
    try {
        MarkableInputStream markStream = new MarkableInputStream(stream);
        stream = markStream;

        long mark = markStream.savePosition(65536); // TODO fix this crap.
        markStream.reset(mark);
        TiApplication.getBitmapOptionsTransformer().transformOptions(markStream, opts, mark);
        b = BitmapFactory.decodeResourceStream(null, null, stream, pad, opts);
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Unable to load bitmap. Not enough memory: " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return b;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

/**
 * Creates and returns a density scaled Bitmap from an InputStream.
 * @param stream an InputStream to read bitmap data.
 * @return a new bitmap instance./*from   w  w  w.j  a va  2s  . c  o m*/
 */
public static Bitmap createDensityScaledBitmap(final InputStream stream) {
    Bitmap b = null;
    try {
        b = BitmapFactory.decodeResourceStream(null, null, stream, null, getScaledBitmapOptions());
    } catch (OutOfMemoryError e) {
        Log.e(TAG, "Unable to load bitmap. Not enough memory: " + e.getMessage());
    }
    return b;
}