[Gambas-user] gb.image: how to keep a rotated image centered

kevinfishburne kevinfishburne at ...1887...
Thu Aug 12 00:05:52 CEST 2010



Jussi Lahtinen wrote:
> 
> There is probably more efficient ways, but quick and dirty...
> 

Great minds must think alike. I didn't receive a notification email about
your post for some reason, but independently developed the same code almost
exactly. Crazy, huh? Your code (and my code) do the trick nicely. Here's
mine: http://old.nabble.com/file/p29413377/gb.image_rotate.tar.bz2
gb.image_rotate.tar.bz2 

PUBLIC SUB Form_Open()

  ' General declarations.
  DIM bg_normal AS Image = Image.Load("grass.png")
  DIM bg_rotated AS Image
  DIM bg_cropped AS Image
  DIM f AS Float
  DIM t AS Float
  DIM frames AS Integer

  ' Assign initial values to variables.
  DrawingArea.Height = Desktop.Height
  DrawingArea.Width = Desktop.Width

  ' Rotate the background and update the drawing area.
  FMain.Show
  t = Timer
  FOR f = 0 TO 6.2831853 * 1 STEP 0.01
    bg_rotated = bg_normal.Rotate(f)
    bg_cropped = bg_rotated.Copy((bg_rotated.Width - 1024) / 2,
(bg_rotated.Height - 1024) / 2, 1024, 1024)
    Draw.Begin(DrawingArea)
      Draw.Image(bg_cropped, 0, 0)
    Draw.End
    frames = frames + 1
    WAIT
  NEXT

  ' Display frames per second rendered.
  PRINT frames / (Timer - t) & " frames per second"

  ' End the program.
  QUIT

END


-----
Kevin Fishburne, Eight Virtues
www:  http://sales.eightvirtues.com http://sales.eightvirtues.com 
e-mail:  mailto:sales at ...1887... sales at ...1887... 
phone: (770) 853-6271
-- 
View this message in context: http://old.nabble.com/gb.image%3A-how-to-keep-a-rotated-image-centered-tp29369608p29413377.html
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list