Hi guys, I am trying to work on something where I set an image in a picturebox and then use getpixel to scan the whole image and find the percentage of the colour I am interested in, in that image.
The problem is that if the image is large then the program hangs, it only works for count of co-ordinates upto (50,50) even then it takes a few seconds to write the results in the text box. I have read on LockBits method but I dont understand how to use it properly on the picturebox as I am new to C++. Can anyone give me an example on how to go about doing this or are there any better alternatives as I will be using this program on microscope images which have a pretty high resolution probably around 1080p or more ?
` int RequiredCount, nonRequiredCount, CountPerc;
Image^ i = pictureBox1->Image;
Bitmap^ b = gcnew Bitmap(i);
For (int y = 0; y < (pictureBox1.Height - 1), y++)
{
For (int x = 0; x < (pictureBox1.Width - 1), x++)
{
Color c = b->GetPixel(x,y);
int k, j, z;
k = c.R;
j = c.G;
z = c.B;
if (k <= 75 && j <= 75 && z <= 75)
{
this->txt1->Text = this->txt1->Text + " | " + c.R.ToString() + "-" + c.G.ToString() + "-" + c.B.ToString();
RequiredCount = RequiredCount + 1;
}
else
{
nonRequiredCount = nonRequiredCount + 1;
}
CountPerc = (RequiredCount / nonRequiredCount) * 100;
this->btnWork->Text = CountPerc.ToString();
}
} `
Thank you.