1

For a program that I'm making in vb.net, I need to have a rectangle, with an image displayed on it, rotate and move around the screen. It needs to move quickly and responsively, so I'm using the standard RectangleShape. The problem here is that vb.net apparently has no in-built function to rotate this rectangle. I'm not really able to use the corresponding Graphics equivalent with the FillRectangle, as it's incredibly laggy on the computer I'm using for this- since it requires constant DrawImage functions for separate bitmaps.

So, is there a way to have a Rectangle that can:

  • Hold an image
  • Be rotated
  • Be moved around the stage in a very cpu-unintensive manner

Thank you

Overt_Agent
  • 510
  • 6
  • 15

1 Answers1

0
Dim mxRotate As New Matrix()

'75 being the arbitrary number I picked to rotate by
mxRotate.Rotate(75, MatrixOrder.Append)

e.Graphics.Transform = mxRotate
e.Graphics.DrawRectangle(YourPen, YourRect)

This can probably help you rotate the image: How to rotate JPEG using Graphics.RotateTransform without clipping

As for performance. I'd imagine all of this will use a little bit of the CPU. Alternatively, you can use DirectX or OpenGL for rendering if that's an option.

Community
  • 1
  • 1
Keith
  • 1,331
  • 2
  • 13
  • 18
  • Ah, see that's the problem. That involves then creating a separate bitmap to hold this image, which has to be redrawn onto the background bitmap at every change, with the background being refreshed. Unfortunately, since the timer handling this is set to fire at 25 ms intervals, it cause large amounts of lag on the test PC, making it unplayable. – Overt_Agent Jul 21 '14 at 18:54
  • I see. However, I probably wouldn't do it based off of a timer, but rather an event, like OnMouseDown if M1 clicked location is < 5 pixels away from a corner, etc. – Keith Jul 21 '14 at 19:22
  • Unfortunately, since it is moved based on keyboard input, it has to be. – Overt_Agent Jul 21 '14 at 19:27
  • Not really supposed to link to code like this, but this guy's code example runs very smoothly and while it's in C#, it doesn't do anything that would bog a CPU down: http://www.codeproject.com/Articles/3319/Image-Rotation-in-NET – Keith Jul 21 '14 at 19:30