简体   繁体   English

如何为Android使用Alpha Blending来混合2张照片

[英]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. 我知道我需要使用Alpha混合为每个像素显示每张照片的一部分,例如:在某个像素上,我将显示一张图片的30%,另一张照片的70%。 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); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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