Graphics Image Editor

Hello guys I will show you how to create a graphics image editor in Visual Basic.Net. This code is a image editor that can apply some effects like, zoom, sharpen, smooth, rotate, etc. All this using the .NET classes can operate pixel by pixel. The code shows also how to use clipboard class and open/save dialog and environments. Result

Sample Code

For the MDI Form Script
  1. Begin
  2. VB.MDIForm MDIForm1
  3. BackColor = &H8000000C&
  4. Caption = "MDIForm1"
  5. ClientHeight = 3120
  6. ClientLeft = 75
  7. ClientTop = 405
  8. ClientWidth = 4650
  9. LinkTopic = "MDIForm1"
  10. End
  11. Attribute VB_Name = "MDIForm1"
  12. Attribute VB_GlobalNameSpace = False
  13. Attribute VB_Creatable = False
  14. Attribute VB_PredeclaredId = True
  15. Attribute VB_Exposed = False
  16. Private Sub MDIForm_Initialize()
  17. Me.Icon = LoadPicture(App.Path & "\p.ico")
  18. cx = GetSystemMetrics(SM_CXSCREEN)
  19. cy = GetSystemMetrics(SM_CYSCREEN)
  20. width = Form1.ScaleX(cx - 8, vbPixels, vbTwips)
  21. height = Form1.ScaleY(cy - 85, vbPixels, vbTwips)
  22. Form1.Move 0, 0, width, height
  23. MDIForm1.WindowState = 2
  24. End Sub
And for the Resize Script for image
  1. Begin
  2. VB.Form resize
  3. BorderStyle = 1 'Fixed Single
  4. Caption = "Resize"
  5. ClientHeight = 2745
  6. ClientLeft = 45
  7. ClientTop = 375
  8. ClientWidth = 4155
  9. LinkTopic = "Form2"
  10. MaxButton = 0 'False
  11. MinButton = 0 'False
  12. ScaleHeight = 183
  13. ScaleMode = 3 'Pixel
  14. ScaleWidth = 277
  15. StartUpPosition = 1 'CenterOwner
  16. Begin VB.CommandButton Command2
  17. Caption = "Cancel"
  18. Height = 375
  19. Left = 1800
  20. TabIndex = 4
  21. Top = 2160
  22. Width = 975
  23. End
  24. Begin VB.CommandButton Command1
  25. Caption = "Ok"
  26. Height = 375
  27. Left = 360
  28. TabIndex = 3
  29. Top = 2160
  30. Width = 975
  31. End
  32. Begin VB.Frame Frame1
  33. Caption = "New Size"
  34. Height = 1815
  35. Left = 120
  36. TabIndex = 0
  37. Top = 240
  38. Width = 3855
  39. Begin VB.CheckBox Check1
  40. Caption = "Maintain Ascept Ratio"
  41. Height = 255
  42. Left = 240
  43. TabIndex = 10
  44. Top = 1320
  45. Value = 1 'Checked
  46. Width = 1935
  47. End
  48. Begin VB.TextBox Text3
  49. Height = 285
  50. Left = 2280
  51. Locked = -1 'True
  52. TabIndex = 9
  53. Top = 1320
  54. Width = 615
  55. End
  56. Begin VB.TextBox Text2
  57. Height = 375
  58. Left = 960
  59. MaxLength = 4
  60. TabIndex = 2
  61. Top = 720
  62. Width = 1335
  63. End
  64. Begin VB.TextBox Text1
  65. CausesValidation= 0 'False
  66. Height = 375
  67. Left = 960
  68. MaxLength = 4
  69. TabIndex = 1
  70. Top = 240
  71. Width = 1335
  72. End
  73. Begin VB.Label Label5
  74. Caption = "to 1"
  75. Height = 255
  76. Left = 3120
  77. TabIndex = 11
  78. Top = 1320
  79. Width = 375
  80. End
  81. Begin VB.Label Label4
  82. Caption = "Pixels"
  83. Height = 255
  84. Left = 2400
  85. TabIndex = 8
  86. Top = 840
  87. Width = 495
  88. End
  89. Begin VB.Label Label3
  90. Caption = "Pixels"
  91. Height = 255
  92. Left = 2400
  93. TabIndex = 7
  94. Top = 360
  95. Width = 615
  96. End
  97. Begin VB.Label Label2
  98. Caption = "Height"
  99. Height = 255
  100. Left = 240
  101. TabIndex = 6
  102. Top = 720
  103. Width = 495
  104. End
  105. Begin VB.Label Label1
  106. Caption = "Width"
  107. Height = 255
  108. Left = 240
  109. TabIndex = 5
  110. Top = 240
  111. Width = 495
  112. End
  113. End
  114. End
  115. Attribute VB_Name = "resize"
  116. Attribute VB_GlobalNameSpace = False
  117. Attribute VB_Creatable = False
  118. Attribute VB_PredeclaredId = True
  119. Attribute VB_Exposed = False
  120. Option Explicit
  121. Dim aratio As Single
  122.  
  123. Private Sub Command1_Click()
  124. Form1.Picture1.Picture = LoadPicture()
  125. Form1.Picture1.width = Val(Text1.Text)
  126. Form1.Picture1.height = Val(Text2.Text)
  127. StretchBlt Form1.Picture1.hdc, 0, 0, Val(Text1.Text), Val(Text2.Text), Form1.Picture2.hdc, 0, 0, picwidth, picheight, vbSrcCopy
  128. picwidth = Val(Text1.Text)
  129. picheight = Val(Text2.Text)
  130. loading
  131. Unload Me
  132. End Sub
  133.  
  134. Private Sub Command2_Click()
  135. Unload Me
  136. End Sub
  137.  
  138. Private Sub Form_Load()
  139. Text1.Text = picwidth
  140. Text2.Text = picheight
  141. If picheight <> 0 Then aratio = picwidth / picheight: Text3.Text = aratio
  142. End Sub
  143.  
  144. Private Sub Text1_KeyPress(KeyAscii As Integer)
  145.  
  146. If KeyAscii = vbKeyBack Then
  147. ElseIf KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then KeyAscii = 0
  148. End If
  149. End Sub
  150.  
  151. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
  152. If Check1.Value = 1 Then Text2.Text = CInt(Val(Text1) / aratio)
  153. End Sub
  154.  
  155. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  156.  
  157. If Button = vbRightButton Then Button = vbLeftButton
  158. End Sub
  159.  
  160. Private Sub Text2_KeyPress(KeyAscii As Integer)
  161. If KeyAscii = vbKeyBack Then
  162. ElseIf KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then KeyAscii = 0
  163. End If
  164. End Sub
  165.  
  166. Private Sub Text2_KeyUp(KeyCode As Integer, Shift As Integer)
  167. If Check1.Value = 1 Then Text1.Text = CInt(Val(Text2) * aratio)
  168. End Sub
Result This code is just an example, and you can use it freely as a base to build more applications. Enjoy Coding.

Add new comment