• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 330
  • Last Modified:

Rotating an Image control

I have a single icon of a fighter jet that I have specified as the picture of an image control.  I want to make the jet turn left, right, go forward, and backwards.  The problem is, with only one view of the jet, it wouldn't look right having the jet face foward while it flys left.  So, my question is: How can I make the Image control, with my icon in it, rotate a specific direction or amount of degrees.  I don't even know if it's possible (if it's not and you tell me that as an answer, I won't give you any points, heh, sorry), but I thought I'd see.  Thanks in advance,

  • 3
  • 2
1 Solution
First you can't rotate the control directly.

2nd, "No" is still a correct answer to your Q and withholding the pts is poor sportsmanship.

3rd. You can do a workaround. Use Paint or Photo Studio to create four images of the aircraft, each rotated 90 degrees. Load them into a PictureClip and then change the icon as required. If you use Photo Studio you can rotate by angles other than 90, but you're right it'll look odd.


core123Author Commented:
Directly?  Look, all I need to know how to do is rotate the bitmap in it w/o having to save individual pictures for each degree of rotation, then load them into the control :)
That's a non-trivial exercise. You only have to create the temp files once, then when they're in the picture clip they compile right in to your app.

Otherwise, Set up a PictureBox, set AutoSize = True. Load image in. Create 2nd box with X&Y dimensions reversed. Scan thru X/Y in first and read each pixel. Write pixel to 2nd box in Y/X order. This will rotate, but will be dog slow. If image size is reasonable, pictureclip solution will be much faster than trying to do this on the fly. You'll still need to have the reference image so you're looking at a very minor space saving for a large amount of code. For small images code to invert/rotate may exceed what 4x bit image will need!


core123Author Commented:
I need to rotate ALOT of other things besides the fighter alone.  I'd much rather rotate them realtime then spend hours doing it in a graphics program and increasing the size of my executable ten fold.  So from that standpoint, having static bitmap files would instead be a non-trivial exercise.

Besides that, what API would I use to execute the method you described for realtime rotation?

If you're coding a game, then execution speed will be one of the critical design params. You want speed, not execution size. If the images are icon sized (32x32) you can load a *TON* of them in a picture clip and share that same clip among all forms. Dynamic rotation is going to be slow and may cause your game to "cog". The time *you* spend rotating the image files is a one time effort. The time spent rotating images on the fly occurs every time your program is run. You're trading programmer effort for end-user runtime. Generally its a *bad* tradeoff.

From Appleman's book:


VB Declaration

Declare Function PlgBlt& Lib "gdi32" (ByVal hdcDest As Long, lpPoint As _
POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal _
nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As _
Long, ByVal yMask As Long)


Copies a bitmap, transforming it into a parallelogram. This allows you to rotate a bitmap.

Use with VB

No problem.

Parameter      Type/Description
hdcDest      Long—A destination device context for the image.
lpPoint      POINTAPI—The first entry in an array of POINTAPI structures. The first point corresponds to the upper-left corner of a parallelogram. The second point is the upper-right corner and the third point is the lower-left corner. The fourth corner is derived from the first three.
hdcSrc      Long—The source device context for the image.
nXSrc, nYSrc      Long—The x,y coordinate of the upper-left corner of the source image in logical coordinates.
nWidth, nHeight      Long—The size of the source image in logical coordinates.
hbmMask      Long—An optional handle to a monochrome mask. If specified, only bits that have a corresponding mask value of 1 will be transferred to the destination.
xMask, yMask      Long—The x,y coordinates for the upper-left corner of the area in the mask bitmap to use.
Return Value

Long—Nonzero on success, zero on failure. Sets GetLastError.


Windows NT


If a rotation or shear transform is in effect for the source, the function fails. Use GetDeviceCaps to determine if this function is supported by a device context.



Again, this is going to be relatively s-l-o-w for a "real time" game.


Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now