简体   繁体   中英

how to use alpha blending for android to blend 2 photos

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.

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); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM