Example usage for android.graphics Canvas drawRGB

List of usage examples for android.graphics Canvas drawRGB

Introduction

In this page you can find the example usage for android.graphics Canvas drawRGB.

Prototype

public void drawRGB(int r, int g, int b) 

Source Link

Document

Fill the entire canvas' bitmap (restricted to the current clip) with the specified RGB color, using srcover porterduff mode.

Usage

From source file:com.dunrite.xpaper.utility.Utils.java

/**
 * Creates drawable for the wallpaper//www  . ja v a  2  s  .  c  o  m
 * @param context current app context
 * @param foreground foreground drawable
 * @param bgColor color of background
 * @param fgColor color of foreground
 * @param isPreview if this is for the preview or not
 * @return the final, constructed wallpaper
 */
public static Drawable constructWallpaper(Context context, Drawable foreground, int bgColor, int fgColor,
        boolean isPreview) {
    final int WIDTH = 2560;
    final int HEIGHT = 1440;
    Canvas comboImage;
    Bitmap cs, fg;
    Paint fgPaint = new Paint();

    //create bitmap from foreground drawable
    fg = ((BitmapDrawable) foreground).getBitmap();

    if (isPreview)
        cs = Bitmap.createBitmap(WIDTH / 2, HEIGHT / 2, Bitmap.Config.ARGB_8888);
    else
        cs = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    comboImage = new Canvas(cs);

    fgPaint.setFilterBitmap(false);
    fgPaint.setColorFilter(new PorterDuffColorFilter(fgColor, PorterDuff.Mode.SRC_ATOP));

    comboImage.drawRGB(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
    if (isPreview)
        comboImage.drawBitmap(Bitmap.createScaledBitmap(fg, WIDTH / 2, HEIGHT / 2, true), 0, 0, fgPaint);
    else
        comboImage.drawBitmap(fg, 0, 0, fgPaint);

    return new BitmapDrawable(context.getResources(), cs);
}

From source file:com.example.androidmillgame.GamePanel.java

protected void onDraw(Canvas canvas) {// ...................use.active.rendering.to.put.the.buffered.image.on-screen

    try {//from  www. j av  a2s . c o  m
        //...................................................................draw.the.background:.use.the.image.or.a.black.color
        canvas.drawRGB(0, 0, 0);
        canvas.drawBitmap(imgres.getImage("background"), background, backgroundRect, null);
        for (int i = 0; i < 24; i++) {// ..............................................................render.joints
            generatedJoints.Joints[i].Draw(canvas);
        }
        DraggablePoint.Draw(canvas);
        Display.Draw(canvas);
        if (GC.getGameOver())
            canvas.drawBitmap(imgres.getImage("resumeok"), null, resumeRect, null);
        else
            canvas.drawBitmap(imgres.getImage("resumenop"), null, resumeRect, null);
    } catch (Exception e) {
        Log.d(TAG, "Graphics context error: " + e);
    }
}