Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Using HBITMAP from ActiveX controller in CVI

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!

0 Kudos
Message 1 of 9
(4,726 Views)
I would prefer the HBITMAP as it is a Windows object. CVI does not support the MFC, so trying to extract the bitmap from a CPicture might be nasty.
However, there has already been a thread in this forum that covers the usage of HBITMAPs.
Hope this helps, Guenter
0 Kudos
Message 2 of 9
(4,715 Views)

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

0 Kudos
Message 3 of 9
(4,707 Views)
0 Kudos
Message 4 of 9
(4,704 Views)

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,

Andrew McLennan
Applications Engineer
National Instruments
0 Kudos
Message 5 of 9
(4,652 Views)

Hi,

 

thanks a lot for your interest!

Not really, they all point to irrelevant things.

 

 

0 Kudos
Message 6 of 9
(4,647 Views)
Then i will suggest giving more details will help
0 Kudos
Message 7 of 9
(4,644 Views)

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???

0 Kudos
Message 8 of 9
(4,637 Views)

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);
}

0 Kudos
Message 9 of 9
(3,809 Views)