Jump to content
  • Advertisement
Sign in to follow this  
Joey21

I want to rotate a bitmap object in VB NET

This topic is 5413 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm currently using the RotateFlip function from the class System.Drawing. The problem is that the function can only rotate on 90, 180, 270 degrees, and I want to rotate on 5 degrees. Does anyone knows how I could do it in VB? I'm new to the gaming scene and I'm a student in computer science in Canad (province of quebec). Thanks all in advance! :)

Share this post


Link to post
Share on other sites
Advertisement
In VB6 you can't do that. I'm pretty sure it's the same in .NET, but don't take my word for it. If you do manage it, it will probably be as slow as molasses, because controls aren't well... that fast.

You'll probably have to learn a 3D API to do it dynamically, but you could always make another bitmap, manually rotated a little, and fake it. Other than that - no idea (won't say it can't be done) [wink]

Share this post


Link to post
Share on other sites
As the function's name already suggests, RotateFlip doesn't rotate a itmap, it just flips it by swapping the pixels. Try to write your own rotation method. It's not that hard. Allocate a temporary bitmap that has twice the size of the unrotated bitmap (the rotated one will be slightly larger). Next you can simply read each scanline of the unrotated bitmap and rotate it by drawing it non-horizontally to the temporary bitmap:


+-------+ +--------------+
|xoxoxox| => | |
|.......| | xoxox |
|.......| | xo |
+-------+ | |
| |
| |
+--------------+

The slope of the scanline in the temporary bitmap is defined by the angle of rotation (e.g. arctan(angle) - beware of infinities at multiples of 90° degrees!). You can use a fast DDA algorithm or Bresenham for line drawing. If you store the extreme points you can crop the temporary bitmap to its final extensions if you like.

You will get gaps with this method, though, which you can fill by averaging the final image.

Hope this helps,
Pat.

[edit]
You can also be very clever by just taking care of the first quadrant when rotating and just flip x/y for the second, third and fourth quadrant.
[/edit]

Share this post


Link to post
Share on other sites
Quote:
Original post by darookie
As the function's name already suggests, RotateFlip doesn't rotate a itmap, it just flips it by swapping the pixels. Try to write your own rotation method. It's not that hard. Allocate a temporary bitmap that has twice the size of the unrotated bitmap (the rotated one will be slightly larger). Next you can simply read each scanline of the unrotated bitmap and rotate it by drawing it non-horizontally to the temporary bitmap:


+-------+ +--------------+
|xoxoxox| => | |
|.......| | xoxox |
|.......| | xo |
+-------+ | |
| |
| |
+--------------+

The slope of the scanline in the temporary bitmap is defined by the angle of rotation (e.g. arctan(angle) - beware of infinities at multiples of 90° degrees!). You can use a fast DDA algorithm or Bresenham for line drawing. If you store the extreme points you can crop the temporary bitmap to its final extensions if you like.

You will get gaps with this method, though, which you can fill by averaging the final image.

Hope this helps,
Pat.

[edit]
You can also be very clever by just taking care of the first quadrant when rotating and just flip x/y for the second, third and fourth quadrant.
[/edit]



Do you know any good article that explains this well?

Thanks a lot for your help!

Joey

Share this post


Link to post
Share on other sites
Well I don't have any links from the top of my head, but I can tell you about better methods [smile].
Do you want to preserve the bitmap size on rotation (e.g. rotated bitmap being bigger) or do you want your rotaed bitmap to have the same dimensions as your input?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by darookie
Well I don't have any links from the top of my head, but I can tell you about better methods [smile].
Do you want to preserve the bitmap size on rotation (e.g. rotated bitmap being bigger) or do you want your rotaed bitmap to have the same dimensions as your input?


I would like it to have the same dimension as my input...

Thanks,
Joey

Share this post


Link to post
Share on other sites
I just found that you can use RotateTransform(), too [wink].
Here's a (C++) tutorial: Rotating a bitmap. Could be easily translated into VB.NET.

Good luck,
Pat.
[edit]
Just noted that the tutorial is bi-lingual, too. Information is also provided in French [smile]
[/edit]

Share this post


Link to post
Share on other sites
Quote:
Original post by darookie
I just found that you can use RotateTransform(), too [wink].
Here's a (C++) tutorial: Rotating a bitmap. Could be easily translated into VB.NET.

Good luck,
Pat.
[edit]
Just noted that the tutorial is bi-lingual, too. Information is also provided in French [smile]
[/edit]


Thanks a lot for the french article :)

I should be able to translate in in vb.net.

Again, thanks a lot! :)

Share this post


Link to post
Share on other sites
Quote:
I just found that you can use RotateTransform(), too [wink].



I just checked that, and that function is for the graphics class. I want to rotate a bmp that is written on a backbuffer image (graphic).

So, if I use the RotateTransform() function, I'll have to rotate the full backbuffer, and that would change the full map angles, and not only the BMP ones.

Hope you understand what I mean,
Joey

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!