473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Picturebox question

id like to know if its possible. i need to find the location of black and white color in the picturebox. per pixel and store it to array. for example;

there are color black from x1 to y5. i want to store it to array example; pixel[x1,y1],[x1,y2],[x1,y3],[x1,y4],[x1,y5] how can i do it automatically? Tnx in advance
Aug 21 '12 #1
9 2101
Killer42
8,435 Expert 8TB
The code posted in your later question, which converts a picture to grayscale, should be quite capable of examining each pixel and telling you whether it's black or white.

Do you still need further help with this one?
Aug 22 '12 #2
yes sir i still need further help with this one?
Aug 23 '12 #3
Killer42
8,435 Expert 8TB
Not sure exactly what aspect of this you need help with.

Most likely you're looking at a slight variation on your "gray scale" code. For example, let's assume you have a global or form-level two-dimensional array of type Boolean called ThisIsBlack().

Expand|Select|Wrap|Line Numbers
  1. Dim Color As Long
  2. Dim i As Long
  3. Dim j As Long
  4. Picture2.ScaleMode = vbPixels
  5. X = Picture2.ScaleWidth - 1
  6. Y = Picture2.ScaleHeight - 1
  7. ReDim ThisIsBlack (X, Y)
  8. For i = 0 To Y
  9.   For j = 0 To X
  10.     Color = Picture2.Point(j, i)
  11.     If Color = 0& Then
  12.       ThisIsBlack (j, i) = True
  13.     End If
  14.   Next
  15. Next
  16.  
This is just quickly typed here so may need some debugging. but that should populate your array to show which pixels are black.
Aug 24 '12 #4
where can i view the output? on a textbox?
Aug 24 '12 #5
Killer42
8,435 Expert 8TB
That's kind of a tough one to answer. The sample code I provided doesn't produce any output, except for the values in the array.

To see these values, you'd have to display them in some way. For example you might place them in a textbox, show them on another picturebox (Pset), print them to the output window (Debug.Print) or in some other way.
Aug 26 '12 #6
I saw this code made by PsychoCoder
Expand|Select|Wrap|Line Numbers
  1.  
  2.     Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
  3.  
  4.     Private Sub Form_Load()
  5.         pixBox.Picture = LoadPicture("YourPicturePath")
  6.         Dim i As Long, j As Long, nBlack As Long, nWhite As Long, pHdc As Long, tempColor As Long
  7.         Show
  8.         With pixBox
  9.             pHdc = .hdc
  10.             .ScaleMode = 3
  11.             For i = 0 To .ScaleWidth
  12.                 For j = 0 To .ScaleHeight
  13.                     tempColor = GetPixel(pHdc, i, j)
  14.                     If tempColor = vbWhite Then
  15.                         nWhite = nWhite + 1
  16.                     ElseIf tempColor = vbBlack Then
  17.                         nBlack = nBlack + 1
  18.                     End If
  19.                 Next
  20.             Next
  21.         End With
  22.         MsgBox "White : " & nWhite & vbCrLf & "Black : " & nBlack, vbInformation
  23.     End Sub 
  24.  
  25.  
Close enough on what im planning to do. but this one count all the black and white how can manipulate this that it can output the pixel(x,y) of the black and white? Thanks
Aug 26 '12 #7
Killer42
8,435 Expert 8TB
Well, instead of adding up a counter for black or white, you could print out the coordinates (in this case, i and j) and "black" or "white". It all depends on what you want to do with this output. Is it just for testing so you can check the code is working?
Aug 27 '12 #8
Here's the example

the output show the total number of black and white, Now my question is how can i see each pixel of the color black. in the picture x axis i assume the number is the last pixel for white and the y axis for the last pixel for black
Aug 28 '12 #9
i add text1.text for the i and text2.text for the j
Expand|Select|Wrap|Line Numbers
  1.  With Picture2
  2.             pHdc = .hdc
  3.             .ScaleMode = 3
  4.             For i = 0 To .ScaleWidth
  5.                 For j = 0 To .ScaleHeight
  6.                     tempColor = GetPixel(pHdc, i, j)
  7.  
  8.                     If tempColor = vbWhite Then
  9.                         nWhite = nWhite + 1
  10.                         Text1.Text = i
  11.  
  12.                     ElseIf tempColor = vbBlack Then
  13.                         nBlack = nBlack + 1
  14.                         Text2.Text = j
Aug 28 '12 #10

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

Similar topics

2
by: Woody Splawn | last post by:
I just wondering if rather than keeping a database with pictures of employees in it (like a photo field), I'm wondering if instead you could just keep the picture files in your bin directory of a...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
38
by: johnb41 | last post by:
I have a Picturebox that has an image displayed inside. Through code, I was able to have the "whole image" display in it without distortion. (Like a "Fit All" in most any image viewer program) ...
10
by: wandii | last post by:
Hi, I have a table which contains a BLOB field for image. I would like to copy a picture from database directly to a picture box control and I have tried the following: Dim c as Integer c =...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
0
by: A Hoefnagels | last post by:
I am new in this forum but maybe someone can help me out. In a picturebox I can draw shapes with the drawellipse method. How can I copy this to the clipboard. ( With an imagefile there is no...
0
by: dlamar | last post by:
I'm using VB.NET with 2.0 - I have a number of PictureBoxes in my application - all of which use a context menu to change the associated Image to one of 5 options. I need to maintain the state of...
2
by: pat.saunders | last post by:
Hi, I am using Visual Studio 2005 and am using Visual C#. I notice that the program.cs creates an instance of a form and runs it. I have a PictureBox in the form and a Class File x.cs and in the...
5
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the...
1
by: leshka82 | last post by:
I have recently designed a Winform Image drag & drop utility. The approach I took was to have a Panel control serve as a destination for multiple file drop. Once the user dragged & dropped 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.