Skip to content Skip to sidebar Skip to footer

Android Bitmap With Border

I have this function, with this function I can show an image with a little rotation. I'm trying to display a white border arround the bitmap. Matrix m = new Matrix(); m.pos

Solution 1:

I think you should follow these steps:

  1. Create a bitmap that width = yourImageWidth + boderThick and height= yourImageHeight + boderThick
  2. Canvas draw a White rectangle (draw your background first)
  3. Canvas draw your image (you need to center your image)

Maybe you made a mistake when calculating the side, or draw in a wrong order. Remember to use the same canvas when drawing. In your code i see you use c.draw and canvas.draw... That may cause the problem.

Refer to the code below:

Paintpaint=newPaint();
 paint.setColor(Color.WHITE);
 paint.setStrokeWidth(3);
 canvas.drawRect(0, 0, 200, 200, paint);//draw your bg
 canvas.drawBitmap(bitmap, 20, 20, paint);//draw your image on bg

Sorry, i don't have much time to check your calculated size. I hope this can help.

Post a Comment for "Android Bitmap With Border"