Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

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

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:Main.java

public static Bitmap decodeBitmap(Context context, int resourceId) {
    return BitmapFactory.decodeResource(context.getResources(), resourceId);
}

From source file:Main.java

public static Bitmap getBitmapForDensity(Resources res, int displayDpi, int resId) {
    try {/*  www  . ja  v  a  2  s. c  o  m*/
        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

public static SoftReference<Bitmap> getBitmap(Resources resources, int drawable) {
    Bitmap bitmap = BitmapFactory.decodeResource(resources, drawable);
    return new SoftReference<Bitmap>(bitmap);
}

From source file:Main.java

/**
 * Loads the texture with the given id./*  w w  w  .j a  v a 2  s  . co m*/
 *
 * @param context    the application's context
 * @param resourceId the id of the texture
 * @return the texture handle
 */
public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    if (!cachedTextureHandles.containsKey(resourceId)) {
        GLES20.glGenTextures(1, textureHandle, 0);

        if (textureHandle[0] != 0) {
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false; // Pre scaling off

            final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);

            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);

            GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

            bitmap.recycle();

            if (textureHandle[0] == 0) {
                throw new RuntimeException("Error loading texture.");
            }

            cachedTextureHandles.put(resourceId, textureHandle[0]);
        }
    }
    return cachedTextureHandles.get(resourceId);
}

From source file:Main.java

public static Bitmap getBitmap(Resources resources, int drawableResourceId) {
    return BitmapFactory.decodeResource(resources, drawableResourceId);
}

From source file:Main.java

/**
 * Utility method to get bitmap from cache or, if not there, load it
 * from its resource./*from w  w  w  .j a  v  a  2  s .  c om*/
 */
static Bitmap getBitmap(Resources resources, int resourceId) {
    Bitmap bitmap = sBitmapResourceMap.get(resourceId);
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(resources, resourceId);
        sBitmapResourceMap.put(resourceId, bitmap);
    }
    return bitmap;
}

From source file:am.project.x.notification.NotificationMaker.java

public static Notification getFTPRunning(Context context, String title, String text, PendingIntent intent) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context,
            NotificationChannelHelper.getChannelLow(context))
                    .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
                    .setSmallIcon(R.drawable.ic_notification_ftp)
                    .setColor(ContextCompat.getColor(context, R.color.colorPrimary))
                    .setDefaults(NotificationCompat.DEFAULT_ALL)
                    .setCategory(NotificationCompat.CATEGORY_SERVICE)
                    .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                    .setVisibility(NotificationCompat.VISIBILITY_PRIVATE).setAutoCancel(false).setOngoing(true)
                    .setContentTitle(title).setContentText(text).setContentIntent(intent);
    return builder.build();
}

From source file:com.ahmadrosid.lib.baseapp.helper.ImageViewHelper.java

public static void createRounded(Context context, int imgRes, ImageView imageView) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imgRes);
    RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
    rounded.setCornerRadius(bitmap.getWidth());
    imageView.setImageDrawable(rounded);
}

From source file:Main.java

public static int loadTexture(Resources resources, int resource, int internalFormat, boolean flip) {
    int[] textures = s_LOAD_TEXTURE_ID.get();
    if (textures == null) {
        textures = new int[1];
        s_LOAD_TEXTURE_ID.set(textures);
    }/*from   www  . j av a 2  s . co  m*/

    glActiveTexture(GL_TEXTURE0);
    glGenTextures(1, textures, 0);

    int texture = textures[0];
    glBindTexture(GL_TEXTURE_2D, texture);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

    Bitmap bitmap = BitmapFactory.decodeResource(resources, resource);

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();

    if (flip) {
        Matrix matrix = new Matrix();
        matrix.setScale(1, -1);
        matrix.postTranslate(0, height);
        Bitmap flipBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);

        bitmap.recycle();
        bitmap = flipBitmap;
    }

    GLUtils.texImage2D(GL_TEXTURE_2D, 0, internalFormat, bitmap, GL_UNSIGNED_BYTE, 0);

    bitmap.recycle();

    glBindTexture(GL_TEXTURE_2D, 0);

    return texture;
}

From source file:Main.java

/**
 * mask a bitmap//from  w  w w.  ja  va  2s. c  o m
 *
 * @param src the bitmap to mask
 * @param drawableResId a resource id of the mask
 * @return a bitmap
 */
public static Bitmap maskBitmap(Bitmap src, int drawableResId) {
    Bitmap mask = BitmapFactory.decodeResource(_resources, drawableResId);

    return maskBitmap(src, mask, null, null, null, null);
}