| | |
How to GetPixel from Bitmap?
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
I want my program to analyse geometric figures drawn by user. Figures must be filled with color. I have already found algorithm that checks if points are inside figure.
I have problem with getting pixel color.
That is the way I connect points drawn by user:
Messagebox with text "inside" never appears. When I added variable in which was kept color of pixel
I have problem with getting pixel color.
C# Syntax (Toggle Plain Text)
Bitmap rysunek; Pen pisak = new Pen(Color.Black, 1); rysunek = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); pictureBox1.Image = rysunek;
Graphics.FromImage(rysunek).DrawLine(pisak, x[i], y[j]); and that's how I check if pixel is black: C# Syntax (Toggle Plain Text)
if (rysunek.GetPixel(i, j) == Color.Black) { MessageBox.Show("inside"); }
kolor = rysunek.GetPixel(j, i); then after reaching pixel that suppose to be black, value of kolor is:"{Name=ff000000, ARGB=(255, 0, 0, 0)}" What am I doing wrong? Is there other way to check pixel color? Your code looks alright at first sight.
But System.Drawing.Imaging.PixelFormat.Format32bppArgb seems a bit tricky to me (colordept etc.) perhaps try System.Drawing.Imaging.PixelFormat. DontCare
Hope this helps.
But System.Drawing.Imaging.PixelFormat.Format32bppArgb seems a bit tricky to me (colordept etc.) perhaps try System.Drawing.Imaging.PixelFormat. DontCare
Hope this helps.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
Come to think of it. Why not simply use rysunek = new Bitmap(pictureBox1.Width, pictureBox1.Height); ?
"{Name=0, ARGB=(0, 0, 0, 0)}" in every pixel.I've found way to partially solve my problem, when I change
if (rysunek.GetPixel(i, j) == Color.Black) to if (rysunek.GetPixel(j, i) == Color.FromArgb(0, 0, 0) comparison gives proper result.Now I can go on with my program, but it still bothers me why
if (rysunek.GetPixel(i, j) == Color.Black) didn't worked... It took me a while but I think I have found the solution!
Color.Black gives "{Name=Black, ARGB=(255, 0, 0, 0)}"
rysunek.GetPixel(i, j) when it's on a black pixel gives "{Name=ff000000, ARGB=(255, 0, 0, 0)}"
So I think the overloaded == operator for Color, compares the names of the colors, unless you explicitly tell it to compare argb values as you did in your second try.
I think I learned something here!
Color.Black gives "{Name=Black, ARGB=(255, 0, 0, 0)}"
rysunek.GetPixel(i, j) when it's on a black pixel gives "{Name=ff000000, ARGB=(255, 0, 0, 0)}"
So I think the overloaded == operator for Color, compares the names of the colors, unless you explicitly tell it to compare argb values as you did in your second try.
I think I learned something here!
Last edited by ddanbe; Jan 3rd, 2009 at 8:35 am.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- File being used by another process. (C#)
- Simple Text Recognition (C#)
- merging image (C#)
- Paint sample (VB.NET)
- bitmap to unsigned char (C++)
- return array of unsigned ints (C++)
- SetViewPortPixel function - Drawing from Bitmap (C++)
- PictureBox Image.Save Error (VB.NET)
- HDC's (C++)
- image manipulation (C#)
Other Threads in the C# Forum
- Previous Thread: Sleeping without pausing the main thread
- Next Thread: StringFormat
| Thread Tools | Search this Thread |
.net access algorithm api array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox loop mandelbrot math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion platform post programming radians regex remote remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml






