Android Bitmap Create getBackground(int bgcolor)

Here you can find the source of getBackground(int bgcolor)

Description

Helper to create a bitmap to set as imageview or bg

Parameter

Parameter Description
bgcolor a parameter

Return

bitmap

Declaration

public static Bitmap getBackground(int bgcolor) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Main {
    /**//from  ww w. j ava2 s.  c  om
     * Helper to create a bitmap to set as imageview or bg
     * @param bgcolor
     * @return bitmap
     */
    public static Bitmap getBackground(int bgcolor) {
        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;
        }
    }
}

Related

  1. getBitMapFromStream(String filename)
  2. getBitmap(int resId, Context ctx)
  3. getBitmapFromImageView(ImageView theImage)
  4. getBitmapFromResource(Resources resources, int resourceId, int reqWidth, int reqHeight)
  5. getBitmapFromURI(Context context, Uri uri)
  6. makeBitmap(int minSideLength, int maxNumOfPixels, Uri uri, ContentResolver cr, ParcelFileDescriptor pfd, BitmapFactory.Options options)
  7. generateBitmap(int width, int height)