Anton Vakulenko
Anton Vakulenko

Reputation: 23

edsdk c++ code to display liveview images in winapi gui application

I'm working on winapi gui application, that displays liveview images from Canon DSLR with EDSDK API. During testing I successfully display test image with this code:

Rect destRect(15, 15, 620, 413);
HDC hdc = GetDC(hwndDlg);
Graphics graphics(hdc);
Bitmap* myBitmap = new Bitmap(L"test.jpg");
graphics.DrawImage(myBitmap, destRect);
ReleaseDC(hwndDlg, hdc);

But I can't imagine how to replace "test.jpg" with values from this function:

EdsError downloadEvfData(EdsCameraRef camera)
{
    EdsError err = EDS_ERR_OK;
    //    Create memory stream.
    err = EdsCreateMemoryStream(0, &stream);
    //    Create EvfImageRef.
    if(err == EDS_ERR_OK)
    {
        err = EdsCreateEvfImageRef(stream, &evfImage);
    }
    // Download live view image data.
    if(err == EDS_ERR_OK)
    {
        err = EdsDownloadEvfImage(camera, evfImage);
    }

    err = EdsGetPointer(stream, (EdsVoid**) &data);
    if (err != EDS_ERR_OK)
    {
        cout << "Download Live View Image Error in Function EdsGetPointer: " << err << "\n";
        return false;
    }
    err = EdsGetLength(stream, &length);
    if (err != EDS_ERR_OK)
    {
        cout << "Download Live View Image Error in Function EdsGetLength: " << err << "\n";
        return false;
    }

Any help will be highly appreciated!

Upvotes: 0

Views: 415

Answers (1)

Anton Vakulenko
Anton Vakulenko

Reputation: 23

Many thanks to IInspectable. Here the code that displays liveview images on the app's window (plain winapi):

EdsError downloadEvfData(EdsCameraRef camera)
{
    EdsError err = EDS_ERR_OK;
    //    Create memory stream.
    err = EdsCreateMemoryStream(0, &stream);
    //    Create EvfImageRef.
    if(err == EDS_ERR_OK)
    {
        err = EdsCreateEvfImageRef(stream, &evfImage);
    }
    // Download live view image data.
    if(err == EDS_ERR_OK)
    {
        err = EdsDownloadEvfImage(camera, evfImage);
    }
    // get pointer to stream ("image")
    if (err == EDS_ERR_OK)
    {
        err = EdsGetPointer(stream, (EdsVoid**) &data);
    }
    // get length of stream ("image size")
    if (err == EDS_ERR_OK)
    {
        err = EdsGetLength(stream, &length);
    }

    // Display image
    Rect destRect(15, 15, 620, 413);
    HDC hdc = GetDC(GetActiveWindow());
    Graphics graphics(hdc);
    Bitmap* myBitmap = new Bitmap(SHCreateMemStream(data,length), FALSE);
    graphics.DrawImage(myBitmap, destRect);
    ReleaseDC(GetActiveWindow(), hdc);

    // Release stream
    if(stream != NULL)
    {
        EdsRelease(stream);
        stream = NULL;
    }
    // Release evfImage
    if(evfImage != NULL)
    {
        EdsRelease(evfImage);
        evfImage = NULL;
    }
    // delete "image"
    data = NULL;
}

Upvotes: 0

Related Questions