From what I see in the code are you trying to find the QR-code by present a part of the image to the reader and see if it can detect the QR-code. If not found you increase the size one pixel and then try again.
Not sure this is the best method, but having nested loops seems to be a bit cumbersome.
It would probably be better to use one of the vision tools available and try to find the coordinates and the size of the QR-code with a blob-tool or similar.
Unfortunately I am bit rusty using the free vision tool, but there are several libraries you can use, such as
Emgu CV: OpenCV in .NET (C#, VB, C++ and more)[
^] and
Accord.NET Machine Learning Framework[
^]
That said, you could try to improve the code you have by changing the code a little.
IBarcodeReader reader = new BarcodeReader();
int imgw = 100;
int imgh = 100;
while ((imgW < img.Width) && (imgh < img.Height))
{
Bitmap bmp = new Bitmap(img, imgw, imgh);
Qrresult = reader.Decode(bmp);
if (Qrresult != null)
{
QRcodevalue = Qrresult.Text;
bmp.Dispose();
img.Dispose();
return QRcodevalue;
}
bmp.Dispose();
imgw += 100;
imgh += 100;
}
This code should be faster, but maybe not what you are looking for.
Another option is to create a sliding window that moves through the image.
For this you can use the
Bitmap.Clone Method (Rectangle, PixelFormat) (System.Drawing)[
^]
This works if you have knowledge about the size of the QR-code beforehand.
Basically what you do is that you create a rectangle of a fixed size that you move from left to right in rows.
When the the sliding window reaches the right side, the x coordinate is reset to 0 and the y coordinate is incremented by the window height.
This also requires nested loops, so it might not be faster, unless you can foresee where in the whole image it is most likely that the QR-code will appear.
If so, you will have a faster algorithm in most cases, but not all.
I hope you at least got some ideas to move forward.