添加图像时为什么pictureBox1为空白?

时间:2016-12-25 09:58:15

标签: c# .net winforms

我试图在图片框1中尽可能快地播放硬盘中的图像。到目前为止一切都没有用所以我试图使用这种方法,但pictureBox1是空的白色。

在计时器刻度事件中

private void timer3_Tick(object sender, EventArgs e)
        {    
                pictureBox1.Image = GetThumbnail(_files[_indx].FullName);
                timer3.Interval = 40;
                _indx++;
        }

和GetThumbnail方法

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);
    }

0 个答案:

没有答案