Attribute VB_Name = "modPictureTweak" Option Explicit '============================================================================================================= ' ' modPictureTweak Module ' ---------------------- ' ' Created By : Kevin Wilson ' http://www.TheVBZone.com ( The VB Zone ) ' http://www.TheVBZone.net ( The VB Zone .net ) ' ' Last Update : April 01, 2000 ' ' VB Versions : 5.0 / 6.0 ' ' Requires : NOTHING ' ' Description : This module takes a given object that contains a picture and flips it, rotates it, or inverts ' it's colors. For this to work, the specified object must have the hDC, Picture, ScaleWidth, ' ScaleHeight, and MousePointer properties along with the CLS, PaintPicture, and Refresh methods. ' ' Applies To : Form ' PictureBox ' Printer ' PropertyPage ' UserControl ' UserDocument ' ' Example Use : ' ' PictureFlip Picture1, Hor_And_Vert ' PictureInvert Picture1 ' PictureRotate Picture1, Picture2, 45 ' '============================================================================================================= ' ' LEGAL: ' ' You are free to use this code as long as you keep the above heading information intact and unchanged. Credit ' given where credit is due. Also, it is not required, but it would be appreciated if you would mention ' somewhere in your compiled program that that your program makes use of code written and distributed by ' Kevin Wilson (www.TheVBZone.com). Feel free to link to this code via your web site or articles. ' ' You may NOT take this code and pass it off as your own. You may NOT distribute this code on your own server ' or web site. You may NOT take code created by Kevin Wilson (www.TheVBZone.com) and use it to create products, ' utilities, or applications that directly compete with products, utilities, and applications created by Kevin ' Wilson, TheVBZone.com, or Wilson Media. You may NOT take this code and sell it for profit without first ' obtaining the written consent of the author Kevin Wilson. ' ' These conditions are subject to change at the discretion of the owner Kevin Wilson at any time without ' warning or notice. Copyright© by Kevin Wilson. All rights reserved. ' '============================================================================================================= 'Public Enum FlipOrientations ' Horizontal = 0 ' Verticle = 1 ' Hor_And_Vert = 2 'End Enum Public Const Pi = 3.14159265359 Public Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long Public Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long Public Declare Function StretchBlt Lib "gdi32" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long ' Function that will flip a picture depending on how the user specifies Public Function PictureFlip(ByRef PictureObject As Object, ByVal FlipOrientation As FlipOrientations) On Error Resume Next Dim TheWidth As Single Dim TheHeight As Single TheWidth = PictureObject.ScaleWidth TheHeight = PictureObject.ScaleHeight If Horizontal Then PictureObject.PaintPicture PictureObject.Picture, TheWidth, 0, -TheWidth, TheHeight ElseIf Verticle Then PictureObject.PaintPicture PictureObject.Picture, 0, TheHeight, TheWidth, -TheHeight ElseIf Hor_And_Vert Then PictureObject.PaintPicture PictureObject.Picture, TheWidth, TheHeight, -TheWidth, -TheHeight End If End Function ' Function that will invert the colors of a picture Public Function PictureInvert(ByRef PictureObject As Object) On Error Resume Next PictureObject.PaintPicture PictureObject.Picture, 0, 0, , , , , , , vbDstInvert End Function ' Function that will take the given picture in an object and rotation (0-360) ' and put the rotated picture into another object Public Function PictureRotate(ByVal PictureSource As Object, ByRef PictureDestination As Object, ByVal RotateAngle As Single) On Error Resume Next Dim a As Single Dim n As Long Dim r As Long Dim c0 As Long Dim c1 As Long Dim c2 As Long Dim c3 As Long Dim c1x As Long Dim c1y As Long Dim c2x As Long Dim c2y As Long Dim p1x As Long Dim p1y As Long Dim p2x As Long Dim p2y As Long Dim pic1hDC As Long Dim pic2hDC As Long Dim Theta As Double Dim TheNumber As Single ' Get the valid Theta for rotation If RotateAngle > 360 Then MsgBox "Rotation angle can not be greater than 360", vbOKOnly + vbExclamation, " Invalid Rotation Angle" Exit Function ElseIf RotateAngle < 0 Then MsgBox "Rotation angle can not be less than 0", vbOKOnly + vbExclamation, " Invalid Rotation Angle" Exit Function End If TheNumber = 180 / RotateAngle Theta = Pi / TheNumber ' Ready the recieving object Screen.MousePointer = vbHourglass PictureDestination.MousePointer = vbHourglass PictureSource.MousePointer = vbHourglass PictureDestination.Cls ' Start calculations for rotation c1x = PictureSource.ScaleWidth \ 2 c1y = PictureSource.ScaleHeight \ 2 c2x = PictureDestination.ScaleWidth \ 2 c2y = PictureDestination.ScaleHeight \ 2 If c2x < c2y Then n = c2y Else n = c2x End If n = n - 1 pic1hDC = PictureSource.hDC pic2hDC = PictureDestination.hDC For p2x = 0 To n For p2y = 0 To n If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x) End If r = Sqr(1& * p2x * p2x + 1& * p2y * p2y) p1x = r * Cos(a + Theta) p1y = r * Sin(a + Theta) c0 = GetPixel(pic1hDC, c1x + p1x, c1y + p1y) c1 = GetPixel(pic1hDC, c1x - p1x, c1y - p1y) c2 = GetPixel(pic1hDC, c1x + p1y, c1y - p1x) c3 = GetPixel(pic1hDC, c1x - p1y, c1y + p1x) If c0 <> -1 Then SetPixel pic2hDC, c2x + p2x, c2y + p2y, c0& End If If c1 <> -1 Then SetPixel pic2hDC, c2x - p2x, c2y - p2y, c1& End If If c2 <> -1 Then SetPixel pic2hDC, c2x + p2y, c2y - p2x, c2& End If If c3 <> -1 Then SetPixel pic2hDC, c2x - p2y, c2y + p2x, c3& End If Next Next Screen.MousePointer = vbDefault PictureDestination.MousePointer = vbDefault PictureDestination.Refresh End Function