Hello I would like to create a circular image witch has a small border and inside loads the users profile picture, just like google plus android application does.
The problem is that I need to set that image in as a drawable top of a Button, so I have found this code:
public BitmapDrawable putOverlay(Bitmap bitmap, Bitmap overlay) {
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(overlay, 0, 0, paint);
return new BitmapDrawable(bitmap);
}
witch is supposed to overlay one bitmap (users pic) over another bitmap (oval shaped) but the think is that a) the circular bitmap is over the user’s profile pic, and b) the user’s profile pic is too large.
Any suggestions on how to do this or if I am at least on the right way is much appreciated.
UPDATE
I have managed to show the two images using this code:
public BitmapDrawable putOverlay(Bitmap bitmap, Bitmap overlay) {
int width = overlay.getWidth()-50;
int height = overlay.getHeight()-50;
Bitmap b = Bitmap.createScaledBitmap(bitmap, width, height,true);
Canvas canvas = new Canvas(overlay);
canvas.save();
canvas.translate(width,height);
Matrix matrix = new Matrix();
canvas.drawBitmap(overlay, matrix, null);
canvas.restore();
canvas.drawBitmap(b,matrix, null);
BitmapDrawable completeImage = new BitmapDrawable(getResources(),overlay);
return completeImage;
}
the problem is that the profile picture is not aligned into the circulare image.Its like the profile picture is drawn from the same x,y position the circulare image is drawn.
Also please note that the profile picture is loaded using :
bitmap = BitmapFactory.decodeStream((InputStream) new URL(imagepath).getContent());
Use this code (first scales the profile pic then applies the overlay)
I didn’t quite get what you meant in problem a that the overlay is on top of the profile pic