get Stroke Bitmap - Android Graphics

Android examples for Graphics:Bitmap Transform

Description

get Stroke Bitmap

Demo Code


//package com.java2s;

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;

public class Main {

    public static Bitmap getStrokeBitmap(Bitmap mBitmap, int color, int x,
            int y) {
        int width = mBitmap.getWidth();
        int height = mBitmap.getHeight();
        Bitmap mAlphaBitmap = Bitmap.createBitmap(width, height,
                Config.ARGB_8888);/*from w ww .  j  a  va2 s.com*/
        Canvas mCanvas = new Canvas(mAlphaBitmap);
        Paint mPaint = new Paint();

        mPaint.setColor(Color.BLUE);
        Bitmap alphaBitmap = mBitmap.extractAlpha();
        mCanvas.drawBitmap(alphaBitmap, 0, 0, mPaint);

        Rect srcRect = new Rect(0, 0, width, height);
        Rect innerRect = new Rect(srcRect);
        innerRect.inset(x, y);
        mCanvas.drawBitmap(mBitmap, srcRect, innerRect, mPaint);

        return mAlphaBitmap;
    }
}

Related Tutorials