Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rotating an Image control

Posted on 1999-07-13
5
Medium Priority
?
327 Views
Last Modified: 2013-12-25
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,

-Chris
0
Comment
Question by:core123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 150 total points
ID: 1495288
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.

M

0
 

Author Comment

by:core123
ID: 1495289
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 :)
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1495290
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!

M

0
 

Author Comment

by:core123
ID: 1495291
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?

0
 
LVL 12

Expert Comment

by:mark2150
ID: 1495292
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:

PlgBlt

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)

Description

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.

Platform

Windows NT

Comments

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.

Example

BMRotate.vbp

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

M

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question