【发布时间】:2009-12-31 03:19:26
【问题描述】:
我正在尝试使用 Image 和 BitmapSource 从原始数据创建位图以在 WPF 中显示:
Int32[] data = new Int32[RenderHeight * RenderWidth];
for (Int32 i = 0; i < RenderHeight; i++)
{
for (Int32 j = 0; j < RenderWidth; j++)
{
Int32 index = j + (i * RenderHeight);
if (i + j % 2 == 0)
data[index] = 0xFF0000;
else
data[index] = 0x00FF00;
}
}
BitmapSource source = BitmapSource.Create(RenderWidth, RenderHeight, 96.0, 96.0, PixelFormats.Bgr32, null, data, 0);
RenderImage.Source = source;
但是,对 BitmapSource.Create 的调用会引发 ArgumentException,说“值不在预期范围内”。这不是这样做的方法吗?我没有正确拨打电话吗?
【问题讨论】:
标签: c# bitmapsource stride