Android Utililty Methods Bitmap Create

List of utility methods to do Bitmap Create

Description

The list of methods to do Bitmap Create are organized into topic(s).

Method

BufferedImagecreateCompatibleImage(int width, int height)
create Compatible Image
return getGraphicsConfiguration().createCompatibleImage(width,
        height);
BufferedImagecreateCompatibleImage(BufferedImage image, int width, int height)
create Compatible Image
return getGraphicsConfiguration().createCompatibleImage(width,
        height, image.getTransparency());
BitmapgetBitMapFromStream(String filename)
get Bit Map From Stream
Bitmap bitmap = null;
try {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    bitmap = BitmapFactory.decodeFile(filename, options);
    System.gc();
    return bitmap;
} catch (Exception ex) {
...
BitmapgetBitmap(int resId, Context ctx)
get Bitmap
int mLargeIconWidth = (int) ctx.getResources().getDimension(
        android.R.dimen.notification_large_icon_width);
int mLargeIconHeight = (int) ctx.getResources().getDimension(
        android.R.dimen.notification_large_icon_height);
Drawable d = ctx.getResources().getDrawable(resId);
Bitmap b = Bitmap.createBitmap(mLargeIconWidth, mLargeIconHeight,
        Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
...
BitmapgetBitmapFromImageView(ImageView theImage)
get Bitmap From Image View
return ((BitmapDrawable) theImage.getDrawable()).getBitmap();
BitmapgetBitmapFromResource(Resources resources, int resourceId, int reqWidth, int reqHeight)
get Bitmap From Resource
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(resources, resourceId, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
        reqHeight);
options.inJustDecodeBounds = false;
Bitmap image = BitmapFactory.decodeResource(resources, resourceId,
        options);
...
BitmapgetBitmapFromURI(Context context, Uri uri)
get Bitmap From URI
try {
    Bitmap bitmap = MediaStore.Images.Media.getBitmap(
            context.getContentResolver(), uri);
    return bitmap;
} catch (IOException e) {
    throw new IllegalArgumentException(
            "Error creating bitmap from URI");
BitmapgetBackground(int bgcolor)
Helper to create a bitmap to set as imageview or bg
try {
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap bitmap = Bitmap.createBitmap(2, 2, config);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(bgcolor);
    return bitmap;
} catch (Exception e) {
    return null;
...
BitmapmakeBitmap(int minSideLength, int maxNumOfPixels, Uri uri, ContentResolver cr, ParcelFileDescriptor pfd, BitmapFactory.Options options)
Make a bitmap from a given Uri, minimal side length, and maximum number of pixels.
Bitmap b = null;
try {
    if (pfd == null)
        pfd = makeInputStream(uri, cr);
    if (pfd == null)
        return null;
    if (options == null)
        options = new BitmapFactory.Options();
...
BitmapgenerateBitmap(int width, int height)
generate Bitmap
Bitmap bitmap = Bitmap.createBitmap(width, height,
        Bitmap.Config.ARGB_8888);
int t = (int) (255.0 * Math.random());
int r = (int) (255.0 * Math.random());
int g = (int) (255.0 * Math.random());
int b = (int) (255.0 * Math.random());
int offset1 = (int) (255 * Math.random());
int offset2 = (int) (255 * Math.random());
...