Scanner :Scanning image of a Picture control to a Rich Text Box

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Vineeth K Vineeth K is offline Offline Oct 19th, 2009, 8:45 am |
0
Hello friends i made a small program like a scanner it will scan an image file to a Rich Text Box.
My friend helped me in providing the code to access the pixels of an image.Hope you will like the code.

Try it ....



This need :

Reference files :

Visual Basic For Applications
Visual Basic runtime objects and procedures
Visual basic objects and procedures
OLE Automation

Add

1 - Rich Text Box - Rt1
2 - One Common Dialog Control named cmd
3 - 2 Command Buttons
4 - One Picture Box &
5 - 2 HScroll s

Try to make the Picture control Atuosize to false.
Attached Thumbnails
Scanner.jpg  
Quick reply to this message  
Visual Basic 4 / 5 / 6 Syntax
  1. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
  2. Dim drawtag As String
  3. Function Pencil(col1 As Long) As Single
  4. Dim R As Single
  5. Dim G As Single
  6. Dim B As Single
  7. R = col1 And 255
  8. G = (col1 And 65280) \ 256&
  9. B = (col1 And 16711680) \ 65535
  10. Pencil = (R + B + G) / 765
  11. End Function
  12. Function Brush(col1 As Long) As Long
  13. Dim R As Single
  14. Dim G As Single
  15. Dim B As Single
  16. R = col1 And 255
  17. G = (col1 And 65280) \ 256&
  18. B = (col1 And 16711680) \ 65535
  19. Brush = RGB(R, G, B)
  20. End Function
  21.  
  22. Private Sub Command1_Click()
  23. On Error GoTo Err
  24. Dim Ix, Iy As Integer
  25. Dim col1 As Long
  26. Dim col2 As Single
  27. Dim col3 As String
  28.  
  29. rt1.SelFontName = "Lucida Console"
  30. rt1.SelFontSize = 2
  31. rt1.Text = vbNewLine
  32. rt1.Enabled = False
  33.  
  34. For Iy = 1 To HScroll1.Value
  35. For Ix = 1 To HScroll2.Value
  36.  
  37. col1 = GetPixel(Picture1.hdc, Ix, Iy)
  38. col2 = Pencil(col1)
  39. col3 = Mid(drawtag, Len(drawtag) - Int(col2 * (Len(drawtag) - 1)), 1)
  40.  
  41. rt1.SelStart = Len(rt1.Text) - 2
  42. rt1.SelLength = 1
  43. rt1.SelText = col3
  44. rt1.SelStart = Len(rt1.Text) - 2
  45. rt1.SelLength = 1
  46. rt1.SelColor = Brush(Picture1.Point(Ix + 1, Iy))
  47.  
  48. Next
  49. rt1.SelText = vbNewLine
  50. DoEvents
  51. Next
  52. Err:
  53. rt1.Enabled = True
  54. End Sub
  55. Private Sub Command2_Click()
  56. On Error Resume Next
  57. Dim filename As String
  58. cmd.ShowOpen
  59. filename = cmd.filename
  60. Picture1.Picture = LoadPicture(filename)
  61. End Sub
  62. Private Sub Form_Load()
  63. drawtag = "#"
  64. End Sub
0
pawaninfinite pawaninfinite is offline Offline | Oct 20th, 2009
why can't i found u earlier
 
0
Riju Thomas Riju Thomas is offline Offline | Oct 27th, 2009
excellent
 
 

Message:


Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC