12-06-2008 05:09 PM
I am trying to use the GetScaledPanelDisplayBitmap() function to generate clips of a view of a panel, but I am having severe difficulties with it. Take the following code segment, applied to a panel sized 1200x800 (W x H):
height = -1; width = -1;
GetScaledPanelDisplayBitmap (panHan, VAL_FULL_PANEL, MakeRect (0, 0, 300, 400), height, width, &bitmap);
GetBitmapData (bitmap, 0, 0, &x, &y, 0, 0, 0);
This works as expected, returning a full-sized clip of the selected area. I need to scale this clip downwards to generate thumbnails, so I have been adjusting the values of height and width in accordance with the function help. So::
height = 300; width = 400;
GetScaledPanelDisplayBitmap (panHan, VAL_FULL_PANEL, MakeRect (0, 0, 300, 400), height, width, &bitmap);
GetBitmapData (bitmap, 0, 0, &x, &y, 0, 0, 0);
yields the values x = 133 and y = 113, in agreement with the calculation (x = width / PANEL_WIDTH * area.width) as described in the function help. So far, so good. But when I scale some values up, I get problems. This works OK:
height = 300; width = 400;
GetScaledPanelDisplayBitmap (panHan, VAL_FULL_PANEL, MakeRect (0, 0, 800, 1200), height, width, &bitmap);
GetBitmapData (bitmap, 0, 0, &x, &y, 0, 0, 0);
giving the expected x value of 400. But, when I change the panel width to 2400, and keep everything else the same, I now get a width of 235, not the 200 that the calculation expects. It gets even worse: with small values, the offset of the selection area (the (0, 0) in the MakeRect ) makes no difference to the final result. With larger values, non-zero offsets begin to have an effect on the final bitmap sizes. In other words, the calculation completely breaks down for larger values and I am finding it impossible to calculate the scaling factors.
At first I though the actual viewable screen size (on a 1024 x 768 display) was having an impact possibly due to clipping the selection area, but the 1200 x 800 example which actually worked OK disproves this. In any case, I would expect any clipping to make the final size smaller, but it is larger than expected. I have struggled with this for quite a while now - I cannot figure out what is happening. Can anyone shed any light on what is going wrong with the function/calculation for large values? (Numeric overflow?)
Mike
Solved! Go to Solution.
12-09-2008 03:16 AM
Hello Mike,
I made some fast tests on a sample panel in an application of mine and I cannot reproduce the behaviour you are seeing. For example:
SetPanelAttribute (panel, ATTR_WIDTH, 2400);
SetPanelAttribute (panel, ATTR_HEIGHT, 800);
GetScaledPanelDisplayBitmap (panel, VAL_FULL_PANEL, MakeRect (0, 0, 800, 1200), 300, 400, &bitmap);
GetBitmapData (bitmap, NULL, NULL, &x, &y, NULL, NULL, NULL);
returns the exact 200x300 pixels as expected, so I am to suggest you to place a breakpoint on GetScaledPanelDisplayBitmap line and check that the values you are passing are actually the one you think (this suggestion supposing that those values come from some calculation that may be incorrect, or that they may be altered during program execution).
With reference to Rect offset, I observed that large offset have an effect on bitmap dimensions when they reduce the area clipped: I suppose that the lower right corner of the clipped area cannot lie outside panel actual dimensions, so if you are passing an offset that would move it outside panel dimensions, the resulting area is clipped to panel height and width, and this results in the outputbitmap being reduced in size. As an example, GetScaledPanelDisplayBitmap (panel, VAL_FULL_PANEL, MakeRect (0, 1200, 800, 1200), 300, 400, &bitmap); returns the usual 200x300 pixels bitmap, but GetScaledPanelDisplayBitmap (panel, VAL_FULL_PANEL, MakeRect (10, 0, 800, 1200), 300, 400, &bitmap); returns 296 pixel instead of 300, being 296 the exact result of the formula considering 790 pixels left of the panel from the offset of 10.
12-09-2008 06:03 AM
Roberto,
I can reproduce Mike's symptoms, using your code. BUT only when I try it on a laptop (1024x768 screen). If I try exactly the same code on my desktop machine (1920x1080 screen) I get the same results as you - it works just fine. Until, that is, I increase the panel width to 4800, when the non-linear problem appears on that machine as well. I can't figure it. ![]()
Mike,
There is a workaround. It is a bit messy, but if you use GetPanelDisplayBitmap () instead, then apply the new bitmap to a new Canvas control (sized the same as the bitmap), you can then use GetScaledCtrlDisplayBitmap () to perform the scaling you want. This does not seem to suffer from the same problems.
JR
12-09-2008 08:22 AM
12-10-2008 03:11 PM
Hi JR - thanks your solution actually works! Maybe the NI gurus can tell us what the problem is with large panels and GetScaledPanelDisplayBitmap, but for now I'll use the workaround.
Mike