Connecting Tech Pros Worldwide Forums | Help | Site Map

Handling Picture Using Picture Box.

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#1   Oct 27 '07
Add two picture boxes to a form.

Set the ScaleMode property of both the pictureboxes to 3-Pixels.

General declaration
--------------------------------
Expand|Select|Wrap|Line Numbers
  1. Const ubx = 1000
  2. Const uby = 500
  3. Dim pixels(1 To ubx, 1 To uby) As Long
  4.  
To copy picture from one picturebox to another pixel by pixel.
============================================

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDCOPY_Click()
  2. Dim X As Integer, Y As Integer
  3. For X = 1 To ubx
  4. For Y = 1 To uby
  5. pixels(X, Y) = Picture1.Point(X, Y)
  6. Next Y
  7. Next X
  8.  
  9. For X = 1 To ubx
  10. For Y = 1 To uby
  11. Picture2.PSet (X, Y), pixels(X, Y)
  12. Next Y
  13. Next X
  14. End Sub
  15.  
  16.  
To copy a Gray Scale picture from one picturebox to another.
============================================

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDGRAY_Click()
  2. Dim X As Integer, Y As Integer
  3. Dim R As Integer, G As Integer, B As Integer, A As Integer
  4. For X = 1 To ubx
  5. For Y = 1 To uby
  6. pixels(X, Y) = Picture1.Point(X, Y)
  7. Next Y
  8. Next X
  9.  
  10. For X = 1 To ubx
  11. For Y = 1 To uby
  12. R = pixels(X, Y) And &HFF
  13. G = ((pixels(X, Y) And &HFF00) / &H100) Mod &H100
  14. B = ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100
  15. A = (R + G + B) / 3
  16. pixels(X, Y) = RGB(A, A, A)
  17. Next Y
  18. Next X
  19. For X = 1 To ubx
  20. For Y = 1 To uby
  21. Picture2.PSet (X, Y), pixels(X, Y)
  22. Next Y
  23. Next X
  24.  
  25. End Sub
  26.  
To make an Embossed copy of the picture from one picturebox to another.
================================================== ====

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDEMBOSS_Click()
  2. Dim X As Integer, Y As Integer
  3. Dim R As Integer, G As Integer, B As Integer, A As Integer
  4.  
  5.  
  6. For X = 1 To ubx
  7. For Y = 1 To uby
  8. pixels(X, Y) = Picture1.Point(X, Y)
  9. Next Y
  10. Next X
  11.  
  12. For X = ubx To 2 Step -1
  13. For Y = uby To 2 Step -1
  14. R = ((pixels(X - 1, Y - 1) And &HFF) - (pixels(X, Y) And &HFF)) + 128
  15. G = (((pixels(X - 1, Y - 1) And &HFF00) / &H100) Mod &H100 - ((pixels(X, Y) And &HFF00) / &H100) Mod &H100) + 128
  16. B = (((pixels(X - 1, Y - 1) And &HFF0000) / &H10000) Mod &H100 - ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100) + 128
  17.  
  18. A = Abs((R + G + B) / 3)
  19.  
  20. pixels(X, Y) = RGB(A, A, A)
  21.  
  22. Next Y
  23. Next X
  24.  
  25. For X = 1 To ubx
  26. For Y = 1 To uby
  27. Picture2.PSet (X - 2, Y - 2), pixels(X, Y)
  28. Next Y
  29. Next X
  30.  
  31. End Sub
  32.  
To make an Engraved copy of the picture from one picturebox to another.
================================================== ====

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDENGRAVE_Click()
  2. Dim X As Integer, Y As Integer
  3. Dim R As Integer, G As Integer, B As Integer, A As Integer
  4. For X = 1 To ubx
  5. For Y = 1 To uby
  6. pixels(X, Y) = Picture1.Point(X, Y)
  7. Next Y
  8. Next X
  9.  
  10. For X = 2 To ubx Step -1
  11. For Y = 2 To uby Step -1
  12. R = ((pixels(X + 1, Y + 1) And &HFF) - (pixels(X, Y) And &HFF)) + 128
  13. G = (((pixels(X + 1, Y + 1) And &HFF00) / &H100) Mod &H100 - ((pixels(X, Y) And &HFF00) / &H100) Mod &H100) + 128
  14. B = (((pixels(X + 1, Y + 1) And &HFF0000) / &H10000) Mod &H100 - ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100) + 128
  15.  
  16. A = (R + G + B) / 3
  17. pixels(X, Y) = RGB(A, A, A)
  18. Next Y
  19. Next X
  20. For X = 1 To ubx
  21. For Y = 1 To uby
  22. Picture2.PSet (X, Y), pixels(X, Y)
  23. Next Y
  24. Next X
  25. End Sub
  26.  
  27.  
To make a Blurred copy of the picture from one picturebox to another.
================================================== ==

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDBLUR_Click()
  2. Dim X As Integer, Y As Integer
  3. Dim R As Integer, G As Integer, B As Integer, A As Integer
  4. For X = 1 To ubx
  5. For Y = 1 To uby
  6. pixels(X, Y) = Picture1.Point(X, Y)
  7. Next Y
  8. Next X
  9.  
  10. For X = 1 To ubx - 1
  11. For Y = 1 To uby
  12. R = Abs((pixels(X + 1, Y) And &HFF) + (pixels(X, Y) And &HFF)) / 2
  13. G = Abs(((pixels(X + 1, Y) And &HFF00) / &H100) Mod &H100 + ((pixels(X, Y) And &HFF00) / &H100) Mod &H100) / 2
  14. B = Abs(((pixels(X + 1, Y) And &HFF0000) / &H10000) Mod &H100 + ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100) / 2
  15.  
  16. pixels(X, Y) = RGB(R, G, B)
  17. Next Y
  18. Next X
  19. For X = 1 To ubx
  20. For Y = 1 To uby
  21. Picture2.PSet (X, Y), pixels(X, Y)
  22. Next Y
  23. Next X
  24.  
  25. End Sub
To Sweep(look hazy) the image in one picturebox to another.
=============================================

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDSWEEP_Click()
  2. Dim X As Integer, Y As Integer
  3. Dim R As Integer, G As Integer, B As Integer, A As Integer
  4. For X = 1 To ubx
  5. For Y = 1 To uby
  6. pixels(X, Y) = Picture1.Point(X, Y)
  7. Next Y
  8. Next X
  9.  
  10. For X = ubx - 1 To 1 Step -1
  11. For Y = uby - 1 To 1 Step -1
  12. R = Abs((pixels(X + 1, Y + 1) And &HFF) + (pixels(X, Y) And &HFF)) / 2
  13. G = Abs(((pixels(X + 1, Y + 1) And &HFF00) / &H100) Mod &H100 + ((pixels(X, Y) And &HFF00) / &H100) Mod &H100) / 2
  14. B = Abs(((pixels(X + 1, Y + 1) And &HFF0000) / &H10000) Mod &H100 + ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100) / 2
  15.  
  16. pixels(X, Y) = RGB(R, G, B)
  17. Next Y
  18. Next X
  19. For X = 1 To ubx
  20. For Y = 1 To uby
  21. Picture2.PSet (X, Y), pixels(X, Y)
  22. Next Y
  23. Next X
  24.  
  25. End Sub
  26.  
To copy the picture from reverse side.from one picturebox to another.
================================================== =

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDREVERSE_Click()
  2. Dim X As Integer, Y As Integer
  3. For X = 1 To ubx
  4. For Y = 1 To uby
  5. pixels(X, Y) = Picture1.Point(X, Y)
  6. Next Y
  7. Next X
  8.  
  9. For X = ubx To 1 Step -1
  10. For Y = uby To 1 Step -1
  11. Picture2.PSet (X, Y), pixels(X, Y)
  12. Next Y
  13. Next X
  14. End Sub
  15.  
To Flip the image from one picturebox in another.
====================================

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDFLIP_Click()
  2. Picture2.PaintPicture Picture1.Picture, Picture1.ScaleWidth, 0, -1 * Picture1.ScaleWidth, Picture1.ScaleHeight
  3. End Sub
  4.  
To Remove the color from the image from one picturebox in another.
================================================== =
Add a text box to the form, to enter the value to remove color.

Add the following code
--------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Private Sub CMDLIGHT_Click()
  2. Dim X As Integer, Y As Integer, addon As Integer
  3. addon = Val(Text1.Text)
  4. Dim R As Integer, G As Integer, B As Integer
  5. For X = 1 To ubx
  6. For Y = 1 To uby
  7. pixels(X, Y) = Picture1.Point(X, Y)
  8. Next Y
  9. Next X
  10.  
  11. For X = 1 To ubx
  12. For Y = 1 To uby
  13. R = pixels(X, Y) And &HFF
  14. G = ((pixels(X, Y) And &HFF00) / &H100) Mod &H100
  15. B = ((pixels(X, Y) And &HFF0000) / &H10000) Mod &H100
  16.  
  17. R = R + addon
  18. If R > 255 Then R = 255
  19. G = G + addon
  20. If G > 255 Then G = 255
  21. B = B + addon
  22. If B > 255 Then B = 255
  23.  
  24. pixels(X, Y) = RGB(R, G, B)
  25. Next Y
  26. Next X
  27.  
  28. For X = 1 To ubx
  29. For Y = 1 To uby
  30. Picture2.PSet (X, Y), pixels(X, Y)
  31. Next Y
  32. Next X
  33. End Sub
  34.  



Reply