Draw a Bitmap and return - Android Graphics

Android examples for Graphics:Bitmap Create

Description

Draw a Bitmap and return

Demo Code


//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;

public class Main {
    static Bitmap generatorContactCountIcon(Context context, Bitmap icon) {
        int iconSize = (int) context.getResources().getDimension(
                android.R.dimen.app_icon_size);
        Bitmap contactIcon = Bitmap.createBitmap(iconSize, iconSize,
                Config.ARGB_8888);/*ww  w  .  j  a va  2 s . c  o m*/
        Canvas canvas = new Canvas(contactIcon);

        Paint iconPaint = new Paint();
        iconPaint.setDither(true);
        iconPaint.setFilterBitmap(true);
        Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight());
        Rect dst = new Rect(0, 0, iconSize, iconSize);
        canvas.drawBitmap(icon, src, dst, iconPaint);
        int contacyCount = 11;
        Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG
                | Paint.DEV_KERN_TEXT_FLAG);
        countPaint.setColor(Color.RED);
        countPaint.setTextSize(20f);
        countPaint.setTypeface(Typeface.DEFAULT_BOLD);
        canvas.drawText(String.valueOf(contacyCount), iconSize - 18, 25,
                countPaint);
        return contactIcon;
    }
}

Related Tutorials