Example usage for android.graphics Bitmap eraseColor

List of usage examples for android.graphics Bitmap eraseColor

Introduction

In this page you can find the example usage for android.graphics Bitmap eraseColor.

Prototype

public void eraseColor(@ColorInt int c) 

Source Link

Document

Fills the bitmap's pixels with the specified Color .

Usage

From source file:Main.java

public static Bitmap getTransparentPlaceholder(int width, int height) {
    Bitmap.Config conf = Bitmap.Config.ALPHA_8;
    Bitmap bmp = Bitmap.createBitmap(width, height, conf);
    bmp.eraseColor(Color.TRANSPARENT);
    return bmp;/*w  ww.  j  ava 2 s  . c o m*/
}

From source file:Main.java

public static Bitmap createPlaceholderBitmap(int width, int height) {
    Bitmap.Config config = Bitmap.Config.ARGB_8888;
    Bitmap placeholderBitmap = Bitmap.createBitmap(width, height, config);
    placeholderBitmap.eraseColor(android.graphics.Color.DKGRAY);
    return placeholderBitmap;
}

From source file:Main.java

public static Bitmap createBitmapFromColor(int color, int width, int height) {
    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    bmp.eraseColor(color);
    return bmp;/* w  w w  .j  a va  2  s  . c  om*/
}

From source file:Main.java

public static Bitmap clearBitmap(Bitmap sourceBitmap) {
    Bitmap newBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(),
            sourceBitmap.getHeight());/*  ww  w  . ja v  a 2 s.c o  m*/
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

/**
 * Returns a plain white bitmap./*from   w ww.j a v  a  2 s  .  c  o  m*/
 * @param width     The width of the bitmap
 * @param height    THe height of the bitmap
 * @return  the plain white bitmap
 */
public static Bitmap getBlankBitmap(int width, int height) {
    Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    image.eraseColor(android.graphics.Color.WHITE);
    return image;
}

From source file:Main.java

/**
 * Method to create a fully-transparent Bitmap using the same size of the source passed as
 * parameter and also the same density./*w  w  w .  j a v  a  2s  .  co m*/
 *
 * @param source The original Bitmap.
 * @return A transparent Bitmap with the same size of the source.
 */
public static Bitmap clear(Bitmap source) {
    Bitmap newBitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
    //to erase the color from a Bitmap, I must use a mutable Bitmap!!!!
    Bitmap mutableBitmap = newBitmap.copy(Bitmap.Config.ARGB_8888, true);
    mutableBitmap.eraseColor(Color.TRANSPARENT);
    return mutableBitmap;
}

From source file:Main.java

/**
 * Writes a simple bitmap to local storage. The image is a solid color with size 400x400
 *//*w w  w .  j a v  a2s  .c om*/
private static void writeSolidColorBitmapToFile(File file, int color) throws IOException {
    if (!file.exists()) {
        Bitmap bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
        bitmap.eraseColor(color);

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        } finally {
            if (fos != null) {
                fos.close();
            }
        }
    }
}

From source file:Main.java

public static Bitmap createBitmapFromView(View view) {
    // Clear any focus from the view first to remove any cursor
    view.clearFocus();/* w w  w.j  a v a2  s.  c  om*/
    Bitmap drawingBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    drawingBitmap.eraseColor(Color.TRANSPARENT);
    Canvas canvas = new Canvas(drawingBitmap);
    view.draw(canvas);
    return drawingBitmap;
}

From source file:Main.java

/**
 * Method to scale {@code sourceBitmap}, maintaining the same original size of the bitmap,
 * but with a transparent frame and the scaled and centered {@code sourceBitmap} inside.
 *
 * @return/*  w ww .  j  a va 2s . com*/
 */
public static Bitmap scaleInsideWithFrame(Bitmap mutableBitmap, float factor, int color) {
    Bitmap clearBitmap = mutableBitmap.copy(Bitmap.Config.ARGB_8888, true);
    clearBitmap.eraseColor(color);

    Bitmap resizedInsideBitmap = scaleBitmapByFactor(mutableBitmap, factor);

    int frameWidth = clearBitmap.getWidth();
    int frameHeight = clearBitmap.getHeight();
    int imageWidth = resizedInsideBitmap.getWidth();
    int imageHeight = resizedInsideBitmap.getHeight();

    Canvas canvas = new Canvas(clearBitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    paint.setAntiAlias(true);
    canvas.drawBitmap(resizedInsideBitmap, (frameWidth - imageWidth) / 2, (frameHeight - imageHeight) / 2,
            paint);
    return clearBitmap;
}

From source file:Main.java

public static Bitmap createBitmap(Bitmap bitmap, final String s) {
    bitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.parseColor(s));
    return bitmap;
}