开发者

Error : Object is currently in use elsewhere.

I have developed an application the continuous read image stream from a DSLR camera.

while (!liveViewExit)
        {
            // Create a Memory Stream 
            stream = new IntPtr();

            // Get the bitmap image from the DSLR
            bmp = GetEvfImage(stream);


            if (bmp != null)
            {

                // Crop the image.
                picImage = (System.Drawing.Image)bmp.Clone(new Rectangle(10, 0, 492, 768), bmp.PixelFormat);
                try
                {
                    if (picImage != null)
                        this.picLiveView.Image = (System.Drawing.Image)picImage.Clone();
                }
                catch (Exception ex)
                {
                    Utility.HandleError(ex);
                }


            }
        }

After running a while, I have this error for this line of code:

   this.picLiveView.Image = (System.Drawing.Image)picImage.Clone();


Object is currently in use elsewhere.(   at System.Drawing.Image.get_FrameDimensionsList()
   at System.Drawing.ImageAnimator.CanAnimate(Image image)
   at System.Drawing.ImageAnimator.ImageInfo..ctor(Image image)
   at System.Drawing.ImageAnimator.Animate(Image image, EventHandler onFrameChangedHandler)
   at System.Windows.Forms.PictureBox.Animate(Boolean ani开发者_StackOverflow社区mate)
   at System.Windows.Forms.PictureBox.Animate()
   at System.Windows.Forms.PictureBox.InstallNewImage(Image value, ImageInstallationType installationType)
   at System.Windows.Forms.PictureBox.set_Image(Image value)

I think the picLiveView PictureBox control is not yet ready to accept new image. Any idea how on detect if PictureBox is still in used.

// Added:

It is a single thread. I think the picturebox is not fast enough to process the picture object in the while loop.


Are multiple threads updating the picLiveView image? If so that would explain this problem. Just use one thread instead, and serialize the update - alternatively you could use a lock to access picLiveView:

private readonly object myLock = new object();
...


if (picImage != null)
{
   lock(myLock)
   {
      this.picLiveView.Image = (System.Drawing.Image)picImage.Clone();
   }
} 


I know am late...but try this, if someone have same issue..

if (bmp != null)
            {

                // Crop the image.
                picImage = (System.Drawing.Image)bmp.Clone(new Rectangle(10, 0, 492, 768), bmp.PixelFormat);

    **Bitmap img = new Bitmap(picImage);
    picImage.Dispose();
    picImage = null;**

      try
                {
                    if (picImage != null)
                        **this.picLiveView.Image = img;**
                }
                catch (Exception ex)
                {
                    Utility.HandleError(ex);
                }


            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜