LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Image rotation

Hi,
I need to plot a ship shape on a canvas and then rotate it by a custom
angle.
I need also fine rotation, so that I can't pre-allocate several
bitmaps for several angles.
I have done it pixel by pixel with trigonometric rotation, using
CanvasDrawPoint and CanvasGetPixel, but it is very slow. Does anyone
know how to do it faster? Regards.
0 Kudos
Message 1 of 4
(3,780 Views)
Most of the delay is probably going into drawing the individual points. A simple thing you can do to improve drawing efficiency is to use the batch drawing feature of the canvas (check out the CanvasStartBatchDraw function). It greatly reduces the overhead of each individual call to a drawing function.
If you can't use batch drawing (if, for example, you need to other types of drawing to your panel interspersed with drawing your canvas image) then you should look at the ATTR_DRAW_POLICY attribute of the canvas, and see which trade-offs might be beneficial to you.

A better approach, however, especially if your image data is nice and compact, might be to draw your pixels via a bitmap. This would also have the benefit of improving the efficiency of obtaining the o
riginal data. Instead of using CanvasGetPixels/CanvasDrawPoint, this is what you can do:

GetCtrlBitmap...
GetBitmapInfo...
GetBitmapData...
(modify the data _in memory_ while applying your rotation algorithm)
SetBitmapData...
CanvasDrawBitmap...
DiscardBitmap...

If the bounding rect of the data would change after the rotation, then you can't use SetBitmapData. Instead you should use NewBitmap and pass it the modified data array. In that case, you might also need to clear the area of the original image in that canvas.

The only thing to look out for is that, when you modify the bitmap data, most likely you'll be dealing with multiple bytes per pixel. This shouldn't be very difficult, though. Just copy the (R,G,B) values as a whole, and be careful when calculating your pixel offsets. There will also be some padding at the end of each row of pixels.

Luis Gomes
NI
0 Kudos
Message 2 of 4
(3,780 Views)
Thaks for your help.
Could you suggest me where to find informations about Bitmap
structure? I do not know how to access pixels after calling
GetCtrlBitmap...
GetBitmapInfo...
GetBitmapData...
All examples provided with CVI do not modify bitmaps, only copy
to/from clipboard and/or files.
Thank you
0 Kudos
Message 3 of 4
(3,780 Views)
The pixels are all contained in the "Bits" array that you pass to GetBitmapData.
The best place to get information on manipulating the pixels is the GetBitmapData function panel itself, especially the Bits parameter help.
If you're looking for a higher level description of bitmaps, you should go to the CVI online help and bring up the "Using Bitmap Objects" topic.

- luis
0 Kudos
Message 4 of 4
(3,780 Views)