473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,397 developers and data experts.

Handling Picture Using Picture Box.

debasisdas
8,127 Expert 4TB
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.  
Oct 27 '07 #1
0 7212

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel...
7
by: Matthias Czapla | last post by:
Hi! Whats the canonical way for handling raw data. I want to read a file without making any assumption about its structure and store portions of it in memory and compare ranges with constant...
6
by: nick4soup | last post by:
I have read the CGI FAQ 'How can I avoid users hitting "submit" twice' (on http://www.htmlhelp.org/faq/cgifaq.3.html#19 ) which essentially says you have to detect it at the server, using a...
2
by: Matt | last post by:
Thank you for trying to help. I am a newbie trying to learn access. I am creating a database in access97 with few picture fields in it. After some research I decided to use the famous "External...
2
by: Ulrike | last post by:
I need to bind in (thumbnail-sized) pictures into an Access Database in such a way that there is one picture for each record (abt. 3000 records on the whole). Ideally, the pictures should show on...
2
by: Lyn | last post by:
I am trying to embed a picture into a Bound Object Frame (Me!Photograph) with the following code which is based on MS article http://support.microsoft.com/?id=158941: strPathname =...
8
by: Robert | last post by:
I am creating a database that will have a large number of images in it and I would like some input as to the best way to handle them. Each record in my database will have a one-to-many...
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
2
by: nguyenminhhai | last post by:
Hi everyone, I'm reading "The C++ Programming Language" (Bjarne Stroustrup, 3rd edition). At page 193, he said "Doing error handling using the same level of abstraction as the code that caused the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.