Overlay Images In Android
I have two images that I want to merge into one. (Eg 'House.png' on top of 'street.png') How do i achieve this in Android? I just want to merge the images and export them to a file
Solution 1:
I'd try something like:
publicstatic Bitmap mergeImages(Bitmap bottomImage, Bitmap topImage) {
finalBitmapoutput= Bitmap.createBitmap(bottomImage.getWidth(), bottomImage
.getHeight(), Config.ARGB_8888);
finalCanvascanvas=newCanvas(output);
finalPaintpaint=newPaint();
paint.setAntiAlias(true);
canvas.drawBitmap(bottomImage, 0, 0, paint);
canvas.drawBitmap(topImage, 0, 0, paint);
return output;
}
(not tested, I just wrote it here, might be some simple errors in there)
Basically what you do is create a 3rd empty bitmap, draw the bottom image on it and then draw the top image over it.
As for saving to a file, here are a few examples: Save bitmap to location
Solution 2:
You can do like this...............
public Bitmap Overlay(Bitmap Bitmap1, Resources paramResources, Bitmap Bitmap2, int alpha)
{
Bitmapbmp1= Bitmap.createScaledBitmap(Bitmap2, Bitmap1.getWidth(), Bitmap1.getHeight(), true);
Bitmapbmp2= Bitmap.createBitmap(Bitmap1.getWidth(), Bitmap1.getHeight(), Bitmap1.getConfig());
PaintlocalPaint=newPaint();
localPaint.setAlpha(alpha);
CanvaslocalCanvas=newCanvas(bmp2);
MatrixlocalMatrix=newMatrix();
localCanvas.drawBitmap(Bitmap1, localMatrix, null);
localCanvas.drawBitmap(bmp1, localMatrix, localPaint);
bmp1.recycle();
System.gc();
return bmp2;
}
Post a Comment for "Overlay Images In Android"