For an application I need to display a photo on the screen, and over it show each frame of the photo i'm taking now through the camera. I know I need to use Alpha blending to show part of each photo for each pixel, for example: on a certain pixel i'll display 30% of one pic and 70% of the other. Can I please get an explanation on how this could be done.
Asked
Active
Viewed 856 times
1 Answers
0
To answer my own question, it can be done by accessing each pixel on both Bitmaps. After that, I needed to give each Bitmap it's precentage of the final Bitmap, then I displayed the changes on a new Bitmap.
public void blend(View v){
operation= Bitmap.createBitmap(bmp.getWidth(),
bmp.getHeight(),bmp.getConfig());
for(int i=0; i<bmp.getWidth(); i++){
for(int j=0; j<bmp.getHeight(); j++){
int p = bmp.getPixel(i, j);
int p2 = bmp2.getPixel(i, j);
int r = Color.red(p);
int g = Color.green(p);
int b = Color.blue(p);
int r2 = Color.red(p2);
int g2 = Color.green(p2);
int b2 = Color.blue(p2);
r=(r+r2)/2;
g=(g+g2)/2;
b=(b+b2)/2;
operation.setPixel(i, j, Color.argb(Color.alpha(p), r, g, b));
}
}
img.setImageBitmap(operation);
}

Jonah G
- 91
- 1
- 1
- 14
-
does PorterDuff.Mode.SRC_OVER give the same result as your formula? – CrackerKSR May 29 '23 at 18:59