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
9 2101
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?
yes sir i still need further help with this one?
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(). -
Dim Color As Long
-
Dim i As Long
-
Dim j As Long
-
Picture2.ScaleMode = vbPixels
-
X = Picture2.ScaleWidth - 1
-
Y = Picture2.ScaleHeight - 1
-
ReDim ThisIsBlack (X, Y)
-
For i = 0 To Y
-
For j = 0 To X
-
Color = Picture2.Point(j, i)
-
If Color = 0& Then
-
ThisIsBlack (j, i) = True
-
End If
-
Next
-
Next
-
This is just quickly typed here so may need some debugging. but that should populate your array to show which pixels are black.
where can i view the output? on a textbox?
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.
I saw this code made by PsychoCoder -
-
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
-
-
Private Sub Form_Load()
-
pixBox.Picture = LoadPicture("YourPicturePath")
-
Dim i As Long, j As Long, nBlack As Long, nWhite As Long, pHdc As Long, tempColor As Long
-
Show
-
With pixBox
-
pHdc = .hdc
-
.ScaleMode = 3
-
For i = 0 To .ScaleWidth
-
For j = 0 To .ScaleHeight
-
tempColor = GetPixel(pHdc, i, j)
-
If tempColor = vbWhite Then
-
nWhite = nWhite + 1
-
ElseIf tempColor = vbBlack Then
-
nBlack = nBlack + 1
-
End If
-
Next
-
Next
-
End With
-
MsgBox "White : " & nWhite & vbCrLf & "Black : " & nBlack, vbInformation
-
End Sub
-
-
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
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?
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
i add text1.text for the i and text2.text for the j - With Picture2
-
pHdc = .hdc
-
.ScaleMode = 3
-
For i = 0 To .ScaleWidth
-
For j = 0 To .ScaleHeight
-
tempColor = GetPixel(pHdc, i, j)
-
-
If tempColor = vbWhite Then
-
nWhite = nWhite + 1
-
Text1.Text = i
-
-
ElseIf tempColor = vbBlack Then
-
nBlack = nBlack + 1
-
Text2.Text = j
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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)
...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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: 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,...
|
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...
| |