【发布时间】:2016-01-25 18:02:01
【问题描述】:
我必须从整数值中绘制图像。它们存储在List<int>[]。
该列表有 5081 个数组,每个数组有 2048 个值。每个值都在 0-1000 之间,一个 int 是一个像素的颜色,所以它是灰度的。
我知道如何用 setpixel 来做,但这太慢了。
for (int y = 0; y < channelId.Length; y++) {
for (int x = 0; x < channelId[y].Count; x++) {
int myColor = (channelId[y].ElementAt(x) * 255) / 1000;
if (myColor > 255) {
myColor = 255;
} else if (myColor < 0) {
myColor = 0;
}
bmp.SetPixel(x, y, Color.FromArgb(myColor, myColor, myColor));
}
}
我知道这里有类似的问题如何更快地绘制位图,但他们已经有了位图。我必须根据我的价值观绘制图像。
【问题讨论】:
-
@stuartd 虽然链接的问题大致相同,但它专门标记为
wpf(并且接受的答案肯定是wpf,因为它使用ImageSource和WriteableBitmap,而不是Bitmap正如对这个问题的预期)