barnhill / barcodelib

C# Barcode Image Generation Library
Apache License 2.0
733 stars 238 forks source link

A generic error occurred in GDI+. in WPF.Net c# #145

Closed nasusonetrick closed 2 years ago

nasusonetrick commented 2 years ago
            Barcode b = new Barcode();
            System.Drawing.Image img = b.Encode(BarcodeLib.TYPE.EAN13, "038000356216", Color.Black, Color.White, 400, 200);

            // Store image in some path with the desired format
            img.Save(@"C:UserssdkcaDesktopean13_example.png", ImageFormat.Png);

is giving me the error : ( A generic error occurred in GDI+ ) ???

barnhill commented 2 years ago

What version of the .net sdk are you using?

barnhill commented 2 years ago

Also is this correct? img.Save(@"C:UserssdkcaDesktopean13_example.png ...

nasusonetrick commented 2 years ago

im using 4.7 net framework

the issue was that i didn't use MemoryStream with using() clause properly thank you for putting offered to reply and my apologies for wasting your time .

by the way when the code bar Format is not correct it throw an error , anyway to generate the codebar even if the chars count are less than 13 in ( EAN ) TYPE ? or should i check for char.Length < 13 , then i change the type ?! which one that accept small and large range of numbers ??!

also how do i Include the text in the bottoms in the same way you did in your Image example ! any code example ?

barnhill commented 2 years ago

Those exceptions are because they are invalid inputs according to the specs.

barnhill commented 2 years ago

The example app has example code in it. Also no worries on wasting my time. I'm here to try to help 🙂👍

barnhill commented 2 years ago

For large numbers of variable length C128 might be the best option.