Loading ...
Sorry, an error occurred while loading the content.

Re: how to display live view image using c#

Expand Messages
  • geert.vergauwe
    Hi, in the C++ code below you can see how to copy the stream data into a buffer (you can calculate the size from the Image info). I have no idea how different
    Message 1 of 3 , Aug 13, 2008
    View Source
    • 0 Attachment
      Hi, in the C++ code below you can see how to copy the stream data
      into a buffer (you can calculate the size from the Image info).

      I have no idea how different this is to coding it in C#, but maybe it
      points you in the right direction. I think the key is to create a
      global memory stream.

      Geert


      EdsStreamRef StreamRef = NULL;
      EdsEvfImageRef ImageRef = NULL;
      EdsUInt32 DataSize = 0;
      BYTE* ImageData = NULL;
      CImage Image;
      HRESULT hr;

      // Prepare the liveview data stream
      EdsCreateMemoryStream(0, &StreamRef);
      EdsCreateEvfImageRef(StreamRef,&ImageRef);

      // Download the liveview data
      for (int TryAgain = 10; TryAgain > 0; TryAgain--){
      hr = EdsDownloadEvfImage (CameraRef, ImageRef);
      if (hr == EDS_ERR_OBJECT_NOTREADY) Sleep(250);
      else TryAgain = 0;
      }

      // Get the liveview image data and size
      EdsGetPointer(StreamRef,(EdsVoid**)&ImageData);
      EdsGetLength( StreamRef, &DataSize);

      // Copy the data to a global memory stream
      CComPtr<IStream> Stream = NULL;
      HGLOBAL hMem = GlobalAlloc(GHND, DataSize);
      LPVOID pBuff = GlobalLock(hMem);
      memcpy(pBuff, ImageData, DataSize); GlobalUnlock(hMem);
      hr = CreateStreamOnHGlobal(hMem, TRUE, &Stream);

      // Get the bitmap image from the stream
      if ((hr = Image.Load(Stream)) == S_OK){

      // Copy the dib data to the provided buffer
      int Pitch = Image.GetPitch();
      int Height = Image.GetHeight();
      BYTE* pBits = (BYTE*)Image.GetBits();
      if (Pitch < 0) pBits += (Pitch *(Height -1));
      memcpy(pData, pBits, abs(Pitch) * Height);
      }

      // Free resources
      GlobalFree(hMem);
      EdsRelease(StreamRef);
      EdsRelease(ImageRef);


      --- In CanonSDK@yahoogroups.com, "jin" <jinqiang.chen@...> wrote:
      >
      > I need some help on displaying live images using Canon SDK and C#?
      My
      > camera is Canon XSI. I already know how to download evf data and
      get a
      > pointer to the JPEG stream by using EdsGetPointer method. But
      unable to
      > copy the stream data into a byte array.
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.