user1920116
user1920116

Reputation: 89

How can I do it faster (Bitmap from IntPtr, EDSDK)

Now I work on Canon EDSDK for myself. I get liveview image to very slow (5 image per second). How can I do it faster?.

This is my code for getting pointer to image:


    uint _err = EDSDK.EDS_ERR_OK;
    IntPtr imageRef = IntPtr.Zero;
    IntPtr streamRef = IntPtr.Zero;
    IntPtr streamPtr = IntPtr.Zero;
    uint Length = 0;

    _err = EDSDK.EdsCreateMemoryStream(0, out streamRef);
    if (EDSDK.EDS_ERR_OK == _err)
      _err = EDSDK.EdsCreateEvfImageRef(streamRef, out imageRef);

    if (EDSDK.EDS_ERR_OK == _err)
      _err = EDSDK.EdsDownloadEvfImage(_camera, imageRef);          

    if (EDSDK.EDS_ERR_OK == _err)
    {
      // display image
      _err = EDSDK.EdsGetPointer(streamRef, out streamPtr);
      if (EDSDK.EDS_ERR_OK == _err)
        _err = EDSDK.EdsGetLength(streamRef, out Length);
    }   

then I load image to Bitmap and it's very very slow. My code:


    byte[] b = new byte[Length];
    Marshal.Copy(streamPtr, b, 0, (int)Length);
    using ( MemoryStream ac = new MemoryStream(b))
    {
      img = (Bitmap)Image.FromStream(ac);
      ac.Close();
    }

Upvotes: 2

Views: 1153

Answers (2)

Avinash
Avinash

Reputation: 23

Have you tried using the EdsGetImage method to extract the image data from the memory stream?

In order to use this method you will need to create an additional Image Reference from the memory stream after you use the EdsDownloadEvf method (using the EdsCreateImageRef method). You may then use this Image Reference in the EdsGetImage method to extract the uncompressed Image Data.

Upvotes: 0

rossb83
rossb83

Reputation: 1762

libjpeg-turbo, available here http://libjpeg-turbo.virtualgl.org/ will decode in real-time

Upvotes: 1

Related Questions