Spire.Barcode is a professional barcode library specially designed for .NET developers (C#, VB.NET, ASP.NET, .NET Core) and Java developers (J2SE and J2EE) to generate, read and scan 1D & 2D barcodes.

Mon Aug 21, 2017 1:11 pm

Hi,

I am using free Spire.Barcode library.

Problem is, when I am reading barcode from my .pdf file barcodes are read successfully for first time however when reading same file in loop of reading multiple files at a time, I see errors like
- GDI+ generic error
- Parameter is not valid

Please help me to overcome this error. My code is below

using (Stream straem = new FileStream(FileName, FileMode.Open, FileAccess.Read))
{
using (PdfLoadedDocument ldoc = new PdfLoadedDocument(straem, false))
{
for (int i = 0; i < ldoc.Pages.Count; i++)
{
try
{
SizeF pageSize = ldoc.Pages[i].Size;
Bitmap img = ldoc.ExportAsImage(i, new SizeF(pageSize.Width * 3, pageSize.Height * 3), true);
//We are getting error in below function
string[] str = Spire.Barcode.BarcodeScanner.Scan(img, Spire.Barcode.BarCodeType.Code128);
foreach (string item in str)
{
txtProcessed.Text += item + "; ";
}
img.Dispose();
img = null;
}
catch (Exception ex)
{
}
}
}
}

pravinchopade
 
Posts: 7
Joined: Mon Aug 21, 2017 12:56 pm

Tue Aug 22, 2017 4:06 am

Hello,

Thanks for your inquiry.
To help us with a better investigation, could you please share your sample pdf and the images generated on your end?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Aug 22, 2017 7:10 am

Hi,
Thanks for your reply.
I have attached the PDF file and image retrieved from it.
We are processing same file 10 times in a loop to see how this code behaves in a case when we need to process a large number of files.

pravinchopade
 
Posts: 7
Joined: Mon Aug 21, 2017 12:56 pm

Tue Aug 22, 2017 10:11 am

Hello,

Thanks for sharing the file.
I have done a test and always got the correct result.
To help us find out the root, could you please try to directly scan the images generated on your side for several times in a loop. If the issue still exists, please share the exception details.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Aug 22, 2017 11:40 am

We kept all images in one folder and processed with Spire.Barcode;
below is the Sample code which we are processing in a loop.

Code: Select all
 string[] files = Directory.GetFiles(@"C:\Users\Pravin\Desktop\TestFile");
            foreach (string item1 in files)
            {
                try
                {
                    string[] str = Spire.Barcode.BarcodeScanner.Scan(item1, Spire.Barcode.BarCodeType.Code128);
                    foreach (string item in str)
                    {
                        txtProcessed.Text += item + "; ";
                    }
                }
                catch (Exception ex)
                {
                    txtException.Text += ex.Message + ": "+ex.StackTrace+";  ";
                }
            }


While in the process it throws exceptions:
1.
Bitmap region is already locked.
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format, BitmapData bitmapData)
at System.Drawing.Bitmap.LockBits(Rectangle rect, ImageLockMode flags, PixelFormat format)
at sprᝢ.ᜀ(spr᜝ A_0)
at sprᠺ.ᜁ(spr᜝ A_0)
at sprᠺ.ᜀ(spr᜝ A_0)
at spr៻.ᜀ.ᜊ()
at spr៻.ᜀ.ᜡ()
at spr៻.᜝()
at Spire.Barcode.BarcodeScanner.Scan(String fileName, BarCodeType barcodeType)

2.
Out of memory
at System.Drawing.Bitmap..ctor(String filename)
at spr៻..ctor(String A_0, sprᤘ A_1)
at Spire.Barcode.BarcodeScanner.Scan(String fileName, BarCodeType barcodeType)

pravinchopade
 
Posts: 7
Joined: Mon Aug 21, 2017 12:56 pm

Wed Aug 23, 2017 8:06 am

Hello,

Thanks for sharing the details.
Strangely, with the same environment, the issue didn't occur on my side and the process only takes around 30% of my mormory. Could you please check your memory occupation when processing?
Looking forward to your reply.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Aug 23, 2017 8:15 am

Hi,

Thanks for your Reply.
When I'm running my application, it is taking 30+% of CPU usage and Memory usage goes beyond 90%.
And I'm running that code in a loop, 10 times calling the same function.
And in a loop after some stages, it starts throwing Out of Memory Exception.
You can check for above scenario.
It is my guess that it does not release memory for Bitmaps.

pravinchopade
 
Posts: 7
Joined: Mon Aug 21, 2017 12:56 pm

Wed Aug 23, 2017 10:17 am

Hello,

Thanks for your response.
We will dig into it and reply you ASAP.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Thu Aug 24, 2017 9:55 am

Hello,

Sorry for the late reply.
I have reproduced the issue and referred it to our dev team, once there's any good news, I will let you know.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Mon Aug 28, 2017 6:27 am

Thanks for the update.
Looking forward to hearing back from you.

pravinchopade
 
Posts: 7
Joined: Mon Aug 21, 2017 12:56 pm

Mon Aug 28, 2017 9:38 am

Hello,

Thanks for the reply.
Once there's any progress, I will inform you.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.BarCode