Image to another image

How can I set an image (translucent) over another image?
I need to create a new bitmap and then save it.

Thanks to everyone.

+4
source share
3 answers
Bitmap bitmap1 = null; // define it Bitmap bitmap2 = null; // define it Bitmap resultBitmap = Bitmap.createBitmap(bitmap1.getWidth(), bitmap1.getHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(resultBitmap); c.drawBitmap(bitmap1, 0, 0, null); Paint p = new Paint(); p.setAlpha(127); c.drawBitmap(bitmap2, 0, 0, p); // Your final bitmap is resultBitmap 
+7
source

All you have to do is take two bitmaps and set their borders. Then you need to draw them as on canvas. If you want to set the image as translucent, you need to set the alpha of the image.

This is an example:

  Bitmap bitmap = null; try { bitmap = Bitmap.createBitmap(500, 500, Config.ARGB_8888); Canvas c = new Canvas(bitmap); Resources res = getResources(); Bitmap bitmap1 = BitmapFactory.decodeResource(res, R.drawable.test1); //blue Bitmap bitmap2 = BitmapFactory.decodeResource(res, R.drawable.test2); //green Drawable drawable1 = new BitmapDrawable(bitmap1); Drawable drawable2 = new BitmapDrawable(bitmap2); drawable1.setBounds(100, 100, 400, 400); drawable2.setBounds(150, 150, 350, 350); drawable1.draw(c); drawable2.draw(c); } catch (Exception e) { } return bitmap; } 
+2
source

Create a canvas object from the canvas of the bottom layer. Then draw a translucent bitmap on this canvas. The original Bitmap object will now have a translucent raster map written on top of it.

0
source

All Articles