10-17-2009 02:52 PM
Using HBITMAP from ActiveX controller in CVI
Hi,
I have LabWindows CVI 9.0 and VDM 8.5.
I have successfully created an ActiveX controller in CVI for a video capturing control created in C++.
One of the ActiveX library functions snaps an image and returns its “Window HBITMAP handle” (as ‘long’).
Another function of the ActiveX returns the handle (CAObjHandle) of the MFC ‘CPicture’ object displaying the snapped image.
Is there any way to use either of these handles in CVI for displaying the snapped image?
If none of the above works I guess the only solution would be writing my own ActiveX server function for exporting an array of the image pixel values, which then can be used in CVI for creating a bitmap, right?
Thanks in advance!
10-18-2009 12:25 PM
10-19-2009 01:28 AM
What do you mean "I would prefer the HBITMAP as it is a windows object"?? you mean using it from VC++?
I'm interested on how to use it from CVI (IF there is a way I can do that).
The thread you point has little relation with this question. It referers to: a) VB, 2) LabView, 3) not about ActiveX exporting an HBITMAP handle. It just talks about how to use the HBITMAP from VB.
I want to find out if there is a way to use the HBITMAP handle from CVI.
Thanks again
10-19-2009 02:14 AM
10-27-2009 05:13 AM
Hi Costas,
Thank you for contacting National Instruments. I just wanted to find out if the above suggestions had helped with your application.
Many thanks,
10-27-2009 05:47 AM
Hi,
thanks a lot for your interest!
Not really, they all point to irrelevant things.
10-27-2009 05:56 AM
10-27-2009 06:16 AM
I think the question is quite in clear.
In one sentence:
"Is there a way of using the 'Windows HBITMAP handle' (returned from an ActiveX controller routine) in CVI (not MStudio!!!), for displaying the image that the HBITMAP handle is referred to???
03-17-2015 05:16 AM - edited 03-17-2015 05:19 AM
Hi Costas,
I currently have the same problem.
Here is a code snippet to give an impression of how it could work.
It is just quick and dirty, tested only with 24bit/32bit bmp, no alpha channel ...
Kind regards,
Klaus
//load HBITMAP from file
HBITMAP hBmp = LoadImageA(NULL, "test_02.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBmp)
{
unsigned char* bits;
int idBmp,size, bytePerPixel;
BITMAP bm;
//get information about GDI bitmap
GetObject( hBmp, sizeof(bm), &bm );
//calculate bytes per pixel
if (bm.bmBitsPixel<8)
bytePerPixel=1;
else
bytePerPixel=(bm.bmBitsPixel/8);
//calculate memory size for bits buffer
size=bytePerPixel*bm.bmWidth*bm.bmHeight;
//allocate temporary buffer
bits=(unsigned char*)malloc(size);
//get image bits
size=GetBitmapBits(hBmp,size,bits);
//create a cvi compatible bitmap (id)
NewBitmapEx (bm.bmWidthBytes, bm.bmBitsPixel, bm.bmWidth, bm.bmHeight, NULL, bits, NULL, NULL, &idBmp);
//release temporary memory
free(bits);
DeleteObject(hBmp);
//now cvi bitmap is ready for use
SetCtrlBitmap (panel, PANEL_PICTURE, 0, idBmp);
//release cvi bitmap after usage
DiscardBitmap(idBmp);
}