|
-
Oct 9th, 2003, 08:56 AM
#1
Thread Starter
Registered User
get Pixel color
how do i get the color of a specific point in a picture box?
Last edited by marvinklein; Oct 21st, 2003 at 07:32 PM.
-
Oct 9th, 2003, 08:16 PM
#2
Member
perhaps, get the image object and convert it bitmap. Then u can use GetPixel and SetPixel function
-
Oct 15th, 2003, 07:46 PM
#3
Thread Starter
Registered User
that works if it is an actual image, but what if i have been drawing lines on a form using the pen object and then i want to find if a point on the for has a line going through it?
-
Oct 17th, 2003, 07:58 AM
#4
yay gay
IMO in that way you could do some maths instad of using gdi
\m/  \m/
-
Oct 17th, 2003, 10:28 AM
#5
Thread Starter
Registered User
no, maths won't cut it. do you know of a way toa ctually get the pixel color?
-
Oct 17th, 2003, 11:58 AM
#6
if you want to get the pixel color then you better draw on the actual image in the picturebox. the you can easily do what Volvere said.
want help with that?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Oct 18th, 2003, 02:36 PM
#7
Lively Member
Your problem is solved
VB Code:
'First we get the picturebox's picture
Dim img As New Bitmap(PictureBox1.Image)
'To get the color of a pixel, use this.
'Replace X and Y with the point of the pixel you want to get.
img.GetPixel(x, y)
'To set the color of a pixel, do this.
'Again, replace X and Y with the pixel you want to set, and the color to set it to.
img.SetPixel(x, y, Color)
DannyJoumaa
Advanced VB6 Programmer
Intermediate-Advanced VB .NET Programmer
Intermediate C# Programmer
Intermediate Win32 Developer
Beginner Mac OS X Developer
Contact: [email protected]
Favorite Sayings:
"Every time you open your mouth, you prove your an idiot."
"God is a programmer. Satan is a bug. Life is debugging."
-
Oct 21st, 2003, 07:32 PM
#8
Thread Starter
Registered User
ok, this is the code i am using to draw the line:
myPictureBox.DrawLine(New Pen(Color.Black), x1 , y1, x2, y2)
now this is what i want to do:
Dim my Color as Color = myPictureBox.GetPixel(x, y)
'EXCEPT GetPixel DOSN'T EXIST!
the problem with drawing onto a bitmap contained in the picturebox is that functions like DrawLine don't exist. All you have then is GetPixel and SetPixel!
So, can somebody please try and come up with a function that returns the color of a pixel in an object that is not a bitmap? (Like you can in 6.0 using the Point function)
thanks...
-
Oct 21st, 2003, 08:41 PM
#9
I wonder how many charact
VB Code:
Dim x As Bitmap = PictureBox1.Image
MessageBox.Show(x.GetPixel(10, 10).ToString)
You can still draw on the picturebox itself. And reset your bitmap to the image when you need to get a pixel. IF you need to do this 1000 times a second, this isn't a good solution obviously.
In which case, this article may help you (in C#):
http://msdn.microsoft.com/library/de...rp11152001.asp
Last edited by nemaroller; Oct 21st, 2003 at 08:45 PM.
-
Oct 22nd, 2003, 08:50 AM
#10
Thread Starter
Registered User
that article is perfect for c#, but i'm using vb.net and there are a lot of useful functions that i simply don't have. maybe i should somehow use the image gdi more directly. i've never used gdi, so i don't really know what i'm talking about, so if you know where i can read something about the image gdi that would be really helpful i think.
-
Oct 22nd, 2003, 11:57 AM
#11
Addicted Member
To draw lines, etc., you need to use a Graphics object. The following example shows you how to draw a line using the Graphics object, and how to use a Bitmap object to call GetPixel. The message boxes are only used to indicate that GetPixel does indeed work. To use this code, place it in the Load event of a form. The form must have a picturebox on it named PictureBox1. This is a crude example, but it's good as a demo:
VB Code:
Dim bmp As New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height)
Dim grph As Graphics
grph = Graphics.FromImage(bmp)
grph.DrawLine(New Pen(Color.Red), 0, 0, PictureBox1.Size.Width, PictureBox1.Size.Height)
PictureBox1.Image = bmp
MessageBox.Show("Color at point 0,0 is " & bmp.GetPixel(0, 0).ToString)
MessageBox.Show("Color at point 10,10 is " & bmp.GetPixel(10, 10).ToString)
-
Oct 22nd, 2003, 09:12 PM
#12
Thread Starter
Registered User
thanks a lot eveybody. that last post made everything work.
this issue is now resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|