AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Rotating bitmaps

This procedure works by swapping each pixel's x and y coordiantes. Although we could have used the Point and PSet methods, the SetPixel and GetPixel API funtions are much quicker. The procedure reads in the RGB value for a pixel, swaps the x and y coordinates, then sets it in the second picture.

Declarations

Declare Function SetPixel Lib _
"gdi32" Alias "SetPixelV" _
(ByVal hdc As Long, ByVal x As 
Long, ByVal y As Long, _
ByVal crColor As Long) As Long

Declare Function GetPixel Lib _
"gdi32" (ByVal hdc As Long, _
ByVal x As Long, ByVal y As Long) As Long

Code

Public Sub rotateimage()
Dim x As Long
Dim y As Long

Picture2.Height = Picture1.Width
Picture2.Width = Picture1.Height

For x = 0 To Picture1.Width

For y = 0 To Picture1.Height
Call SetPixel(Picture2.hdc, _
y, x, GetPixel(Picture1.hdc, x, y))
Next

If x Mod 50 = 0 Then
  DoEvents
  Picture2.Refresh
End If

Next

DoEvents
Picture2.Refresh

End Sub

Notes

Make sure that the Scalemode for both Picture1 and Picture2 are set to Pixels, otherwise, you will end up reading a lot of unnecessary points.

Jargon

RGB Value:
The colour code for a pixel. It measures the amout of Red, Green and Blue in a pixel to make the colour.

Pixel:
The smallest graphic unit on the screen.

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/