调用WriteableBitmap.WritePixels方法 [英] Calling the WriteableBitmap.WritePixels method
问题描述
我想打电话给WriteableBitmap.WritePixels方法,但我似乎无法理解的参数。
MSDN文章是很平淡(或者我shuold说......空?),我无法理解如何使用的方法。
I'm trying to call the WriteableBitmap.WritePixels method, but I can't seem to understand the parameters. The MSDN article is very dull (Or shuold I say... null?), and I couldn't understand how to use the method.
编辑:
我试图从这篇文章修改code:
<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=VS.90%29.aspx\">http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28v=VS.90%29.aspx
PixelFormat pf = PixelFormats.Rgba128Float;
WriteableBitmap wb = new WriteableBitmap(width * 5, height * 5, 100, 100, pf, new BitmapPalette(new List<Color> { Color.FromArgb(255, 255, 0, 0) }));
byte[] ColorData = { 0, 0, 0, 0 };
wb.WritePixels(new Int32Rect(0, 0, 1, 1), ColorData, 4, 0);
Background.Source = wb;
在最后一行的调试声称,缓冲液(ColorData)大小不足以前行。
In the line before the last line the debugger claims that the buffer (ColorData) size is not sufficient.
EDIT2:
我又试了一次:
I tried again:
void RefreshGraphics()
{
PixelFormat pf = PixelFormats.Pbgra32;
WriteableBitmap wb = new WriteableBitmap(width * 5, height * 5, 100, 100, pf, new BitmapPalette(new List<Color> { Color.FromArgb(255, 255, 0, 0) }));
byte[] ColorData = new byte[1000];
byte t = 0;
for (int i = 0; i < 1000; i++)
ColorData[i] = t++;
wb.WritePixels(new Int32Rect(0, 0, 10, 10), ColorData, 10, 0);
Background.Source = wb;
}
现在一个值是不是在预期的范围。
堆栈跟踪不会告诉哪一个...
Now a "Value is is not in the expected range." The stackTrace doesn't tell which one...
修改3:
问题解决了!
不知道如何或为何,但code ++工程,(我害怕改变吧...)
Edit 3: Problem Solved! Don't know how or why, but the code works (And I afraid to change it...)
推荐答案
检查高度和宽度的数值。也许字节数组是根本不够大!
Check the values of height and width. Perhaps the byte array is simply not big enough!
这篇关于调用WriteableBitmap.WritePixels方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!