我正试图循环一个位图数组,但是它只会显示一次,然后该数组为空。实际上,您可以在从阵列中删除最后访问的位图的RAM用法中看到它。
代码:
CurrentBuffer++;
var temp = bitmaparray[CurrentBuffer];
if (pictureBox1.Image != null) {
pictureBox1.Image.Dispose();
}
if (CurrentBuffer == BufferFrames)
CurrentBuffer = 1; // bufferframes is the total count of elements -1 in the array
pictureBox1.Image = temp;
// attempt to put the image back in the array again, but still doesn't work
bitmaparray[CurrentBuffer] = temp;
所需的结果是它将按时间顺序一次又一次地显示位图。但是现在它将循环遍历一次,然后数组为空。
我在这里想念什么?
答案 0 :(得分:1)
在每次迭代中,您都将图像分配给pictureBox1.Image
。
pictureBox1.Image = temp;
然后在下一次迭代中,将dispose放在该图像上:
pictureBox1.Image.Dispose();
在这里,pictureBox1.Image
指向bitmaparray
中的图像,因此实际上是从数组中放置图像。
我认为您只需要摆脱Dispose。
(这全部基于Uwe Keim的评论,谢谢)