2011-01-28 2 views
1

나는 DSLR 카메라에서 연속 읽기 이미지 스트림을 응용 프로그램으로 개발했습니다. 오류 : 개체가 현재 다른 곳에서 사용되고 있습니다.

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 animate) 
    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) 

내가 picLiveView PictureBox 컨트롤이 아직 새 이미지를 받아 들일 준비가 아니라고 생각 :

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


      } 
     } 

잠시를 실행 한 후, 나는이 코드 라인이 오류가 있습니다. PictureBox가 아직 사용 중인지 확인하는 방법에 대해 알아보십시오.

// 추가 :

단일 스레드입니다. 나는 picturebox가 while 루프에서 그림 객체를 처리하기에 충분히 빠르지 않다고 생각한다.

+0

[InvalidOperationException - 개체가 현재 다른 곳에서 사용 중입니다 - 빨간색 십자가] (http://stackoverflow.com/questions/1060280/invalidoperationexception-object-is-currently-in-use-elsewhere-red-cross) – John

답변

2

picLiveView 이미지를 여러 스레드에서 업데이트합니까? 그렇다면이 문제를 설명 할 것입니다. 내가 늦게 나는 알고

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


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

특히 UI에 표시되는 경우 잠금 기능이 도움이되지 않습니다. GDI +는 기본적으로 스레드로부터 안전하지 않습니다. – SLaks

0

을 ...하지만 누군가가 같은 문제가있는 경우

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


      } 
..이 시도 : - 그냥 대신에 하나 개의 스레드를 사용하고 업데이트를 직렬화 또는 당신 picLiveView에 액세스하기 위해 잠금 장치를 사용할 수 있습니다
+0

이 코드는 어떻게 문제를 해결합니까? –

관련 문제