Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to plot a bitmap in a CNiGraph control like PlotBitmap() function in Lab Windows CVI

Hi,

I'm programming C++ with Visual Studio 6.0 on Win 2000.

I need to plot a bitmap in a Component Work++ CNiGraph control so I'll be able to zoom in the image at the same time I zoom in the plot area.

All I found was the possibility to display an image on the background of the plot area. The problem is that when I zoom in, the image won't follow the zoom feature.

Is there a way to plot a bitmap with this control like the PlotBitmap() function of LabWindows CVI?

If not, Is there another control in CW++ that would give me that option?

Thanks a lot.

Fred.
0 Kudos
Message 1 of 10
(6,236 Views)
There isn't an EXACT equivalent. To put an image on the CNiGraph, you would want to use the Annotations feature. You can have an image annotation and position it and size it on the graph. You still will NOT be able to use the built in zooming to zoom it automatically, but you will be able to resize and reposition the annotation on the plot area.

The easiest way to do this is at design time in the property pages.

1) Go to annotations tab in graph properties and add an annotation. Make it a picture.

2) Go to images tab and select the annotation in the list. Then you can load a bitmap/icon/metafile into the annotation.

You can also do this programmatically, by loading the image into a CNiPicture class and setting it to the image of an annota
tion.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 10
(6,233 Views)
I Chris,

I've tried your solution but it's not quite what we need.

We've been working a lot with LabWindows in the past but we are now using CW++ for the display it is a lot nicer and we don't have to carry the run-time engine of LabWindows with our applications.

We would be very interested in getting a version of the CNiGraph component with a PlotBitmap() function just like LabWindows function so we would be able to zoom in the image at the same time we zoom in the plot area.

Do you think National Instruments would be interested in develloping such a control for us?

If yes, could you tell me who I should address my request so we can discuss the terms of an agreement.

Thanks a lot.

Frederic Levesque
National Optical Institute
of Canada (NOI)

2740, Einstein street
Ste-Foy (Quebec) Canada
G1P 4S4
0 Kudos
Message 3 of 10
(6,233 Views)
Fred,

We are not prepared at this time to commit to adding this functionality into CNiGraph. We will add it to the list of features that we will consider for a future version of Measurement Studio.

This functionality is, however, implementable outside of the control. I have attached a project that contains a class that derives from CNiGraph and implements a function you can call whenever you need to scale the plot area. The class is CScaleBmpPlotAreaGraph. The assumptions and some instructions for use are documented in ScaleBmpPlotAreaGraph.h.

Please post back if you have any questions about the implementation or how to extend it for your particular application's needs.

David Rohacek
National Instruments
0 Kudos
Message 4 of 10
(6,235 Views)
Hi,

I've been using your bitmap zooming code (it's a life saver).

I have one question though.. I'm trying to change it so I select an area of interest using cursors (and not Zoom Rect YX) ... when i hardcode the call to StretchBlt to always zoom to a predefined offset, width, and length, it works... but when i add a button to the program to call ScalePlotArea (where the StretchBlt call is hardcoded and all the calculation lines are removed) the plot area is not refreshed.

it seems like the bitmap is actually updated, but not refreshed to screen, because when i hold the mouse down and drag over a region of the plot, the zoomed image is refreshed, below.

i hope that made sense. is there a way to add cursors to your project for zooming instead of using Zoom Rect XY? i'm very interested in expanding it like this.

thank you,
Ryan
0 Kudos
Message 5 of 10
(6,184 Views)
You could call CWnd::Invalidate on the CScaleBmpPlotAreaGraph to force the graph to redraw after you scale the bitmap. However, this shouldn't be necessary. CScaleBmpPlotAreaGraph scales the bitmap according to the axis ranges. So, I would expect that in your button callback you set the axis ranges according to the cursor locations and then call CScaleBmpPlotAreaGraph::ScalePlotArea. Setting the axis ranges automatically invalidates the graph, so that will force it to redraw. I have updated the example project to show how this might be done. Let us know if this works for you.
0 Kudos
Message 6 of 10
(6,170 Views)
Hi,

Thank you very much for your fast reply and the code update. It's exactly what I needed.

I made 1 change ... I loop the OnZoomToCursorsButton to give a gradual zoom-in, but only the final zoom is shown (even when I slow the loop down with a slight pause). I tried adding CWnd::Invalidate to the loop, but nothing seems to flush the plot to screen.

Do you know why this could be?

Thanks again,
Ryan
0 Kudos
Message 7 of 10
(6,163 Views)
You need to pump messages in your loop to give the control a chance to process the Windows messages that will cause it to repaint. There are a couple of ways to do this. One is to implement a message pump inside your loop. This is the code that does that:



MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}



An alternative would be to do your incremental zooms on a Windows timer (SetTimer/KillTimer).
0 Kudos
Message 8 of 10
(6,150 Views)

Is there a way to accomplish this in LabVIEW 8.0?  I'm looking to do pretty much this exact same thing, but I can't find any threads that relate to doing this with LabVIEW.

Thanks!

LMEE

0 Kudos
Message 9 of 10
(5,516 Views)
Hi, LMEE.

That question looks like it was addressed in this post. Let me know how that solution works for you -- if it doesn't, I'll keep looking and see what else I can find. Have a nice afternoon!
Sarah K.
Search PME
National Instruments
0 Kudos
Message 10 of 10
(5,504 Views)