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

/**
 * Get a mask of color {@code color} using the alpha channel of {@code source}.
 * @param source Source image containing the shape alpha channel.
 * @param color Color of the shape./* w  w  w  . j a  v a 2s  .c om*/
 * @return A {@link Bitmap} containing the shape of the given color.
 */
private static Bitmap getMask(Bitmap source, int color) {
    Bitmap retVal;

    retVal = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    retVal.eraseColor(color);

    synchronized (canvas) {
        if (maskPaint == null) {
            maskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
            maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
        }

        canvas.setBitmap(retVal);
        canvas.drawBitmap(source, 0, 0, maskPaint);
    }

    return retVal;
}

From source file:com.xiemarc.marcreading.manager.ThemeManager.java

public static Bitmap getThemeDrawable(int theme) {
    Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(),
            Bitmap.Config.ARGB_8888);//from   w w w .ja v a 2s  .  co  m
    switch (theme) {
    case NORMAL:
        bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_white));
        break;
    case YELLOW:
        bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_yellow));
        break;
    case GREEN:
        bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_green));
        break;
    case LEATHER:
        bmp = BitmapFactory.decodeResource(UIUtils.getContext().getResources(), R.drawable.theme_leather_bg);
        break;
    case GRAY:
        bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_gray));
        break;
    case NIGHT:
        bmp.eraseColor(ContextCompat.getColor(UIUtils.getContext(), R.color.read_theme_night));
        break;
    default:
        break;
    }
    return bmp;
}

From source file:com.example.ysh.myapplication.view.readview.ThemeManager.java

public static Bitmap getThemeDrawable(int theme) {
    Bitmap bmp = Bitmap.createBitmap(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight(),
            Bitmap.Config.ARGB_8888);//w w  w.  j  a v  a  2s .  com
    switch (theme) {
    case NORMAL:
        bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_white));
        break;
    case YELLOW:
        bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_yellow));
        break;
    case GREEN:
        bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_green));
        break;
    case LEATHER:
        bmp = BitmapFactory.decodeResource(AppUtils.getAppContext().getResources(),
                R.drawable.theme_leather_bg);
        break;
    case GRAY:
        bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_gray));
        break;
    case NIGHT:
        bmp.eraseColor(ContextCompat.getColor(AppUtils.getAppContext(), R.color.read_theme_night));
        break;
    default:
        break;
    }
    return bmp;
}

From source file:org.wikipedia.page.shareafact.SnippetImage.java

@NonNull
private static Bitmap drawBackground(@Nullable Bitmap leadImageBitmap, @NonNull ImageLicense license) {
    Bitmap resultBitmap;
    if (leadImageBitmap != null && license.hasLicenseInfo()) {
        // use lead image
        resultBitmap = scaleCropToFit(leadImageBitmap, WIDTH, HEIGHT);
    } else {/* w w w .  j  a v  a2  s  .c o m*/
        resultBitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
        final int backgroundColor = 0xff242438;
        resultBitmap.eraseColor(backgroundColor);
    }
    return resultBitmap;
}

From source file:com.github.amlcurran.showcaseview.StandardShowcaseDrawer.java

@Override
public void erase(Bitmap bitmapBuffer) {
    bitmapBuffer.eraseColor(backgroundColour);
}

From source file:com.achillesrasquinha.biblegenerator.ImageGenerator.java

public Bitmap getBitmap(String title, String subtitle, String text) {
    Bitmap bitmap = Bitmap.createBitmap(mImageSize.x, mImageSize.y, Bitmap.Config.ARGB_8888);
    //convert bitmap to card view background color
    bitmap.eraseColor(ContextCompat.getColor(mContext, R.color.cardview_light_background));

    Canvas canvas = new Canvas(bitmap);

    //title//  w  w w . j a  v  a2  s  .com
    mTextPaint.setTextSize(mSizeTitle);
    mTextPaint.setColor(mColor1);
    canvas.drawText(title, mX, mYTitle, mTextPaint);

    //subtitle
    mTextPaint.setTextSize(mSizeSubtitle);
    mTextPaint.setColor(mColor2);
    canvas.drawText(subtitle, mX, mYSubtitle, mTextPaint);

    //since text needs to be wrapped, using a StaticLayout
    mTextPaint.setColor(mColor3);
    //text size same as subtitle size
    StaticLayout layout = new StaticLayout(text, mTextPaint, mImageSize.x - 2 * mX,
            Layout.Alignment.ALIGN_NORMAL, 1.0f, mLineSpacing, false);
    //16dp padding as per material design guidelines
    canvas.translate(mX, mYSubtitle + mX);
    layout.draw(canvas);

    return bitmap;
}

From source file:us.rader.wyfy.QrCodeFragment.java

/**
 * Inflate the <code>View</code>
 * /*from  w ww .  j  a  v  a 2  s  .c  o  m*/
 * @param inflater
 *            <code>LayoutInflater</code>
 * 
 * @param container
 *            <code>ViewGroup</code>
 * 
 * @param savedInstanceState
 *            saved state or <code>null</code>
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.qr_code_fragment, container, false);
    qrCode = (ImageView) view.findViewById(R.id.qr_code);
    Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.WHITE);
    qrCode.setImageBitmap(bitmap);

    qrCode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            shareQrCode();

        }

    });

    view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @SuppressWarnings("deprecation")
        @Override
        public void onGlobalLayout() {

            if (Build.VERSION.SDK_INT < 16) {

                getView().getViewTreeObserver().removeGlobalOnLayoutListener(this);

            } else {

                getView().getViewTreeObserver().removeOnGlobalLayoutListener(this);

            }

            updateQrCode();

        }
    });

    return view;

}

From source file:com.khoai.bus.ui.IconGenerator.java

/**
 * Creates an icon with the current content and style.
 * <p/>//from   w  ww .j av a 2 s .c  o m
 * This method is useful if a custom view has previously been set, or if text content is not
 * applicable.
 */
public Bitmap makeIcon() {
    int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    mContainer.measure(measureSpec, measureSpec);

    int measuredWidth = mContainer.getMeasuredWidth();
    int measuredHeight = mContainer.getMeasuredHeight();

    mContainer.layout(0, 0, measuredWidth, measuredHeight);

    if (mRotation == 1 || mRotation == 3) {
        measuredHeight = mContainer.getMeasuredWidth();
        measuredWidth = mContainer.getMeasuredHeight();
    }

    Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
    r.eraseColor(Color.TRANSPARENT);

    Canvas canvas = new Canvas(r);

    if (mRotation == 0) {
        // do nothing
    } else if (mRotation == 1) {
        canvas.translate(measuredWidth, 0);
        canvas.rotate(90);
    } else if (mRotation == 2) {
        canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
    } else {
        canvas.translate(0, measuredHeight);
        canvas.rotate(270);
    }
    mContainer.draw(canvas);
    return r;
}

From source file:com.color.kid.kidpaint.activity.OptionsActivity.java

protected void initialiseNewBitmap(Drawable drawable) {
    Display display = getWindowManager().getDefaultDisplay();
    float width = display.getWidth();
    float height = display.getHeight();
    Bitmap bitmap = Bitmap.createBitmap((int) width + 200, (int) height, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.WHITE);
    PaintroidApplication.drawingSurface/*  w  w w . j  a v  a 2  s . c  om*/
            .resetBitmap(Util.overlay(bitmap, Util.drawableToBitmap(drawable, this)));
    PaintroidApplication.perspective.resetScaleAndTranslation();
    mCurrentTool = new DrawTool(this, ToolType.BRUSH);
    PaintroidApplication.currentTool = mCurrentTool;
    PaintroidApplication.currentTool.resetInternalState(Tool.StateChange.NEW_IMAGE_LOADED);
    PaintroidApplication.isPlainImage = true;
    PaintroidApplication.isSaved = false;
    PaintroidApplication.savedPictureUri = null;
}

From source file:Main.java

/**
 * Load the image at {@code imagePath} as a {@link Bitmap}, scaling it to
 * the specified size and preserving the aspect ratio.
 * @param imagePath Path of the image to load.
 * @param width Required width of the resulting {@link Bitmap}.
 * @param height Required height of the resulting {@link Bitmap}.
 * @param fill {@code true} to fill the empty space with transparent color.
 * @param crop {@code true} to crop the image, {@code false} to resize without cutting the image.
 * @return {@link Bitmap} representing the image at {@code imagePath}.
 *///from ww w.  ja  v a  2  s .  co m
public static Bitmap loadResizedBitmap(String imagePath, int width, int height, boolean fill, boolean crop) {
    Bitmap retVal;

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inSampleSize = getScale(imagePath, width, height);
    opts.inJustDecodeBounds = false;

    Bitmap image = BitmapFactory.decodeFile(imagePath, opts);

    if (image == null) {
        return null;
    }

    if (image.getWidth() != width || image.getHeight() != height) {
        int scaledWidth = (image.getWidth() * height) / image.getHeight();
        int scaledHeight; // = (image.getHeight() * width) / image.getWidth();
        if ((crop && scaledWidth > width) || (!crop && scaledWidth < width)) {
            scaledHeight = height;
        } else {
            scaledWidth = width;
            scaledHeight = (image.getHeight() * width) / image.getWidth();
        }
        //image = Bitmap.createScaledBitmap(image, scaledWidth, scaledHeight, true);

        Rect src = new Rect(0, 0, image.getWidth(), image.getHeight());
        Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);

        if (fill) {
            retVal = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            dst.offset((width - scaledWidth) / 2, (height - scaledHeight) / 2);
        } else {
            retVal = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
        }
        retVal.eraseColor(Color.TRANSPARENT);

        synchronized (canvas) {
            if (antiAliasPaint == null) {
                antiAliasPaint = new Paint();
                antiAliasPaint.setAntiAlias(true);
                antiAliasPaint.setFilterBitmap(true);
                antiAliasPaint.setDither(true);
            }
            canvas.setBitmap(retVal);
            canvas.drawBitmap(image, src, dst, antiAliasPaint);
        }

        image.recycle();
    } else {
        //No need to scale.
        retVal = image;
    }

    return retVal;
}