NI Home > Community > NI Discussion Forums

LabWindows/CVI

Reply
Member
Robert_Mensah
Posts: 59
0 Kudos

Need sample code using windows BitBlt() function to display image in CVI

Hello all,

 

I need a sample code which uses windows BitBlt() function to display image in CVI

Thank you.

 

Bob.

Member
JD_war_eagle
Posts: 126
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hi Robert,

 

The best way to do this in CVI is to use GetCtrlBitmap() to take the bitmap from the source and then use CanvasDrawBitmap() to then draw the bitmap in the destination canvas. If you want to use the Bitblt function, you may be able to use the GetWindowDC() function in order to retrieve the handle for a panel which you then may be able to use with the Bitblt() function. This may work, however I do not believe individual CVI controls have device context handles so you will not be able to draw to them directly. See these forum posts for more information:

 

http://forums.ni.com/t5/LabWindows-CVI/How-do-I-include-Win32-API-function-BitBlt-in-CVI7-0/td-p/261...
http://forums.ni.com/t5/LabWindows-CVI/Getting-the-hDC-of-a-Canvas-Control/td-p/1079481

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
Member
Robert_Mensah
Posts: 59
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello JD_war_eagle,

 

Thanks for the reply.

The first post you refered me to was initiated by me. I tried the response that was suggested then and I did not succeed. That is why I re-phrased the question this time asking for a sample code.

I hope someone can help with a sample code that works.

Thank you.

 

Bob.

Active Participant
nickb
Posts: 775
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Bob -

 

I recently posted some sample code that uses the BitBlt function.  You can find it here.  Note this is not production quality code - make sure you closely examine the MSDN pages for these functions in order to harden your code.

 

NickB

National Instruments

Member
Robert_Mensah
Posts: 59
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello NickB,

 

Thanks for the response and the code you refered me to.

When I run the code, a panel with "Take Screenshot" button appeared. However, When I pressed on the "Take Screenshot" button nothing happened. I was expecting an image to appear on the panel. Would you please verify the code you posted for me?

Thank you.

 

Bob

Active Participant
nickb
Posts: 775
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Bob -

 

Sorry, I should have explained the code a little bit more.  The intention of the code was to take a screenshot of the panel, and then place the screenshot on the clipboard - essentially replicating Alt+PrtScn.  After pressing the button, you should be able to paste the image of the panel into Paint, or something similar.

 

- Nick

Member
Robert_Mensah
Posts: 59
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Nick,

 

I just verified that the code stores an image of the panel on the clip board like you said. However, I would like to use BitBlt() (not CVI function) to display the image on the panel or, on a canvas on the panel. Would you please help?

Thank you.

 

Bob

Active Participant
nickb
Posts: 775
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Bob -

 

It's not really clear to me why you would need to do this.  Can you explain what you're trying to achieve?  The problem is that CVI is not going to know anything about what you're drawing on a CVI panel, and will likely erase anything you draw when it paints the panel.  If you can describe what you're trying to do, maybe I can help find a more natural CVI answer.

 

- Nick

Member
Robert_Mensah
Posts: 59
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Nick,

 

I want to use BitBlt() function to create transitions to display pictures on a canvas. I have searched CVI functions and non seems to have similar capabilities.

 

Bob 

Active Participant
nickb
Posts: 775
0 Kudos

Re: Need sample code using windows BitBlt() function to display image in CVI

Hello Bob -

 

I'm curious why you'd like to use BitBlt.  What functionality does it offer that you've not seen in the CVI canvas control?

 

It's hard to say without knowing what transitions you're looking for, but the canvas is very capable of animating/transitioning.  The place it can fall a little short is if you require access to the alpha channel for transparency.

 

I put together a short demo for you - maybe it will address some of what you're looking for.  The important functions are CanvasStartBatchDraw, CanvasEndBatchDraw, and CanvasDrawBitmap.  The animation/transition is driven by a simple UI timer.

 

Let me know if you have any questions -

 

NickB

National Instruments