C#_read pixels from png

Merry Christmas all!
I am trying to read .png image.I want to extract each pixel as a vector3d. My code seems to work but it doesn’t give me any values. when i output list count its 0.

Also reading pixels taking lot of time to compute. Is there any faster way?

below is the code! let me know what am I doing wrong.

Bitmap bmp = new Bitmap(“E:\Practice\MERRY CHRISTMAS.png”);
List spots = new List();
for(int i = 0; i < bmp.Width; i++)
for(int j = 0; j < bmp.Height; j++)
Color c = bmp.GetPixel(i, j);
double bright = c.GetBrightness();
if(bright > 1)
spots.Add(new Vector3d(i, j, 0));

A = spots.Count; //this is coming 0

I found the mistake
it should have been like if(bright==1) since i am trying to pick just white color

however computation time still too much! I do not understand what is reason behind it

Hello getpixel is known to be slow. You will find many examples of fastest implementation on internet. If I remember well there must be a fastest method inside grasshopper. Search a bit in old grasshopper forum.

1 Like