WPF WriteableBitmap透明度问题

WPF WriteableBitmap透明度问题,wpf,writeablebitmap,Wpf,Writeablebitmap,首先,我将解释我试图做什么,以防有人提出更好的方法 我需要混合太多的图像使用“颜色”栅栏从photoshop(你知道,混合方法:屏幕,强光,颜色…) 因此,我在执行时生成了我的基本图像(png)和WriteableBitmap(我们称之为颜色掩码)。然后我需要使用“颜色”方法混合这两个图像,并在UI组件中显示结果 到目前为止,我只是想在WriteableBitmap上绘制一些东西,但我面临着alpha通道的意外行为 到目前为止,我的代码是: // variables declaration Wr

首先,我将解释我试图做什么,以防有人提出更好的方法 我需要混合太多的图像使用“颜色”栅栏从photoshop(你知道,混合方法:屏幕,强光,颜色…)

因此,我在执行时生成了我的基本图像(png)和WriteableBitmap(我们称之为颜色掩码)。然后我需要使用“颜色”方法混合这两个图像,并在UI组件中显示结果

到目前为止,我只是想在WriteableBitmap上绘制一些东西,但我面临着alpha通道的意外行为

到目前为止,我的代码是:

// variables declaration
WriteableBitmap img = new  WriteableBitmap(width, height, 96,96,PixelFormats.Bgra32,null); 
pixels = new uint[width * height];

//function for setting the color of one pixel
private void SetPixel(int x, int y, Color c)
    {
        int pixel = width * y + x;

        int red = c.R;
        int green = c.G;
        int blue = c.B;
        int alpha = c.A;

        pixels[pixel] = (uint)((blue << 24) + (green << 16) + (red << 8) + alpha);

    }

//function for paint all the pixels of the image
private void Render()
    {
        Color c = new Color();
        c.R = 255; c.G = 255; c.B = 255; c.A = 50;
        for (int y = 0; y < height; y++)
            for (int x = 0; x < width; x++)
                SetPixel(x, y, c);



        img.WritePixels(new Int32Rect(0, 0, width, height), pixels, width * 4, 0);
        image1.Source = img;  // image1 is a WPF Image in my XAML
    }
//变量声明
WriteableBitmap img=新的WriteableBitmap(宽度、高度,96,96,PixelFormats.Bgra32,null);
像素=新单元[宽度*高度];
//用于设置一个像素颜色的函数
私有void SetPixel(整数x,整数y,颜色c)
{
int像素=宽度*y+x;
int red=c.R;
int绿色=c.G;
int蓝色=c.B;
int alpha=c.A;

像素[像素]=(uint)((蓝色将颜色组件的顺序更改为

pixels[pixel] = (uint)((alpha << 24) + (red << 16) + (green << 8) + blue);

pixels[pixel]=(uint)((alpha)当它们在枚举上以错误的方式写入颜色分量时,完全可以理解。