Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CniPicture and IPictureDisp

I am getting compilation error when trying to create CNiPicture from a IPictureDisp pointer. Appreciate example code showing how to use transform CBitmap to CNiPicture. Thanx.
 
 
0 Kudos
Message 1 of 2
(3,966 Views)

I'm using the GDI+ (Visual Studio 2003 and higher) CImage class to load a bitmap. But once you have the handle to a valid bitmap, try the following

    CImage image;   
    HRESULT hr = image.Load("c:\\rotatetest.bmp");
    if(SUCCEEDED(hr))
    {
        PICTDESC pictDesc;
        memset(&pictDesc, 0, sizeof(pictDesc));
        pictDesc.cbSizeofstruct = sizeof(pictDesc);
        pictDesc.picType = PICTYPE_BITMAP;
        pictDesc.bmp.hbitmap = (HBITMAP)image;
       
        image.Detach();
        CComPtr<IPictureDisp> picture;
        hr = OleCreatePictureIndirect(&pictDesc, IID_IPictureDisp, TRUE, (void**)&picture);
        if (SUCCEEDED(hr))
        {
            CNiPicture pic(picture.Detach(), true);
            m_graph.Annotations.Item(1).Shape.Image.Picture = pic;
        }

    }

I hope this helps

Bilal Durrani
NI
0 Kudos
Message 2 of 2
(3,950 Views)