2
首先,我解释了我想要做的事情,只是在有人提出更好的方法的情况下 我需要使用photoshop中的“颜色”阶梯混合太多图像(您知道,混合方法:屏幕,硬光,颜色...)WPF WriteableBitmap透明度问题
因此,我有我的基础图像(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
}
每当我运行的颜色C.A = 255的代码中,我得到预期的结果。整个图像设置为所需的颜色。但是如果我将c.A设置为不同的值,我会得到奇怪的东西。 如果我把颜色设置为BRGA = 0,0,255,50,我会得到一个几乎黑色的深蓝色。如果我将它设置为BRGA = 255,255,255,50,我会得到一个黄色的...
任何线索!?!?!
在此先感谢!
呀!小混乱hehehehe它现在就像一个魅力!!非常感谢 ! – javirs
完全可以理解,当他们在枚举上错误地编写颜色组件时。 – Andy