user452349
user452349

Reputation: 50

Creating Rectangle around Bitmap

I have an bitmap of 10*15 size now i want to create an bitmap from this existing bitmap with size 20*30 but the increased area should be transparent ,bitmap should not be translated/scaled.

Upvotes: 0

Views: 3845

Answers (4)

chikka.anddev
chikka.anddev

Reputation: 9629

Create first bitmap with this method:

Bitmap b=b.createBitmap (Bitmap source, int x, int y, int width, int height);

Give your height and width and proper x and y values.

Upvotes: 0

Kantesh
Kantesh

Reputation: 875

Bitmap b = Bitmap.createBitmap(
    yourBitmap,
    xMarginYouWant,
    yMarginYouWant,
    yourBitmap.getWidth() + xMarginYouWant * 2,
    yourBitmap.getHeight() + yMarginYouWant * 2
);

Upvotes: 2

N-JOY
N-JOY

Reputation: 7635

I did not get your question.... The heading is "drawing rectangle around bitmap" but there is no description for rectangle in detail. If you want a rectangle then this can be done as follows....

RectF rect = new RectF(x,y,x+width,y+height);  
canvas.drawRect(rect, paint);  

Drawing bitmap refer other answers...

Upvotes: 1

Reuben Scratton
Reuben Scratton

Reputation: 38727

Create a new Bitmap that's 20x30, create a Canvas to hold that bitmap, and then Canvas.drawBitmap() your 10x15 one into it.

Upvotes: 0

Related Questions