C# 为什么pictureBox1在添加图像时为空白色?
我正试图在picturebox1中尽可能快地播放硬盘上的图像。到目前为止,一切都很顺利。所以我尝试使用这个方法,但是pictureBox1是空的白色 计时器计时事件中C# 为什么pictureBox1在添加图像时为空白色?,c#,.net,winforms,C#,.net,Winforms,我正试图在picturebox1中尽可能快地播放硬盘上的图像。到目前为止,一切都很顺利。所以我尝试使用这个方法,但是pictureBox1是空的白色 计时器计时事件中 private void timer3_Tick(object sender, EventArgs e) { pictureBox1.Image = GetThumbnail(_files[_indx].FullName); timer3.In
private void timer3_Tick(object sender, EventArgs e)
{
pictureBox1.Image = GetThumbnail(_files[_indx].FullName);
timer3.Interval = 40;
_indx++;
}
和简略的方法
private const int THUMBNAIL_DATA = 0x501B;
Image GetThumbnail(string path)
{
FileStream fs = File.OpenRead(path);
// Last parameter tells GDI+ not the load the actual image data
Image img = Image.FromStream(fs, false, false);
// GDI+ throws an error if we try to read a property when the image
// doesn't have that property. Check to make sure the thumbnail property
// item exists.
bool propertyFound = false;
for (int i = 0; i < img.PropertyIdList.Length; i++)
if (img.PropertyIdList[i] == THUMBNAIL_DATA)
{
propertyFound = true;
break;
}
if (!propertyFound)
return null;
PropertyItem p = img.GetPropertyItem(THUMBNAIL_DATA);
fs.Close();
img.Dispose();
// The image data is in the form of a byte array. Write all
// the bytes to a stream and create a new image from that stream
byte[] imageBytes = p.Value;
MemoryStream stream = new MemoryStream(imageBytes.Length);
stream.Write(imageBytes, 0, imageBytes.Length);
return Image.FromStream(stream);
}
private const int THUMBNAIL\u DATA=0x501B;
图像缩略图(字符串路径)
{
FileStream fs=File.OpenRead(路径);
//最后一个参数告诉GDI+不加载实际图像数据
Image img=Image.FromStream(fs,false,false);
//如果我们试图读取图像时的属性,GDI+将抛出一个错误
//没有该属性。请检查以确保缩略图属性
//项目存在。
bool propertyFound=false;
for(int i=0;i
在列表中缓存缩略图
。作为Windows中GUI的基本属性,只有在UI线程没有其他事情可做时,才会进行绘制。你的是,它正在努力生成无人会看到的缩略图。如果希望更早地进行绘制,则必须添加pictureBox1.Update()
通常工作5秒钟左右,之后Windows会介入,告诉用户尝试停止疯狂闪烁是行不通的。将缩略图缓存在列表中。Windows中GUI的基本属性是,只有当UI线程没有其他事情做时,才会进行绘制。你的是,它正在努力生成无人会看到的缩略图。如果希望更早地进行绘制,则必须添加pictureBox1.Update()代码>通常工作5秒钟左右,之后Windows会介入,告诉用户试图停止疯狂的闪烁是行不通的。