Important alert: (current site time 7/16/2013 2:08:31 AM EDT)
 

VB icon

______________...:::SIJO Soft Graphic Manipulation:::...___

Email
Submitted on: 2/26/2003 7:04:56 AM
By: SIJO Soft Corp  
Level: Beginner
User Rating: By 4 Users
Compatibility: VB 5.0, VB 6.0
Views: 15962
author picture
(About the author)
 
     Demonstrates three graphics manipulation routines. Flip, Rotate, Mirror

 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :______________...:::SIJO SoftGraphic Manipulation:::...___
'**************************************
Const SRCCOPY = &HCC0020
Const Pi = 3.14159265359
Private Declare Function SetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "GDI32" (ByVal hDC As Integer, ByVal X As Integer, ByVal Y As Integer) As Long
Private Declare Function StretchBlt% Lib "GDI32" (ByVal hDC%, ByVal X%, ByVal Y%, ByVal nWidth%, ByVal nHeight%, ByVal hSrcDC%, ByVal XSrc%, ByVal YSrc%, ByVal nSrcWidth%, ByVal nSrcHeight%, ByVal dwRop&)
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: ______________...:::SIJO SoftGraphic Manipulation:::...___
' Description:Demonstrates three graphics manipulation routines. Flip, Rotate, Mirror
' By: SIJO Soft Corp
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=43559&lngWId=1'for details.'**************************************

' add three command buttons and two pictureboxes. Load a bitmap into picture1 in design
' mode. Set both box to the same size. Routines execute 3 times faster than routines
' found in Microsoft's Knowledge Base.
'Sub Form_Load ()
Picture1.ScaleMode = 3
Picture2.ScaleMode = 3
'End Sub
'Sub Command1_Click ()
'flip horizontal
picture2.Cls
px% = picture1.ScaleWidth
py% = picture1.ScaleHeight
retval% = StretchBlt(picture2.hDC, px%, 0, -px%, py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
'End Su
'Sub Command2_Click ()
'flip vertical
picture2.Cls
px% = picture1.ScaleWidth
py% = picture1.ScaleHeight
retval% = StretchBlt(picture2.hDC, 0, py%, px%, -py%, picture1.hDC, 0, 0, px%, py%, SRCCOPY)
'End Sub
'Sub Command3_Click ()
'rotate 45 degrees
picture2.Cls
Call bmp_rotate(picture1, picture2, 3.14 / 4)
'End Sub
'Sub bmp_rotate (pic1 As PictureBox, pic2 As PictureBox, ByVal theta!)
 ' bmp_rotate(pic1, pic2, theta)
 ' Rotate the image in a picture box.
 'pic1 is the picture box with the bitmap to rotate
 'pic2 is the picture box to receive the rotated bitmap
 'theta is the angle of rotation
 Dim c1x As Integer, c1y As Integer
 Dim c2x As Integer, c2y As Integer
 Dim a As Single
 Dim p1x As Integer, p1y As Integer
 Dim p2x As Integer, p2y As Integer
 Dim n As Integer, rAs Integer
 c1x = pic1.ScaleWidth \ 2
 c1y = pic1.ScaleHeight \ 2
 c2x = pic2.ScaleWidth \ 2
 c2y = pic2.ScaleHeight \ 2
 If c2x < c2y Then n = c2y Else n = c2x
 n = n - 1
 pic1hDC% = pic1.hDC
 pic2hDC% = pic2.hDC
For p2x = 0 To n
For p2y = 0 To n
 If p2x = 0 Then a = Pi / 2 Else a = Atn(p2y / p2x)
 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 xret& = SetPixel(pic2hDC%, c2x + p2x, c2y + p2y, c0&)
If c1& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2x, c2y - p2y, c1&)
If c2& <> -1 Then xret& = SetPixel(pic2hDC%, c2x + p2y, c2y - p2x, c2&)
If c3& <> -1 Then xret& = SetPixel(pic2hDC%, c2x - p2y, c2y + p2x, c3&)
 Next
t% = DoEvents()
Next
'End Sub


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
12/15/2003 2:11:53 PM

this is nice code to work and learn....!
(If this comment was disrespectful, please report it.)

 
11/27/2005 1:48:53 AMCongDan

I want to view those code for VBA, Because I am starting (studying) Visual basic 6.0. Please give it for me !
(If this comment was disrespectful, please report it.)

 
4/15/2007 8:23:50 AMTimo Böhme

do not touch this code!!! very poor coded. Over 10 bad code faults. Not formated, fault in the API declation. Bad using of %. Outcommented Sub's. Not ended sub. and so on. I corrected some important faults: www.goldengel.ch/rotate_Form1.zip

If you post some code, just have a look on it before you post anything please.

Timo
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.