Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: EGENERATE_IMAGE-2: Image size... less than 1 pixel #85

Closed
kinguru opened this issue Apr 8, 2020 · 7 comments
Closed

Exception: EGENERATE_IMAGE-2: Image size... less than 1 pixel #85

kinguru opened this issue Apr 8, 2020 · 7 comments
Assignees

Comments

@kinguru
Copy link

kinguru commented Apr 8, 2020

Hi!
I'm calling a lib like shown below on the screenshot and getting exception about 1px.
How should I generate a barcode?

image

Thank you

@binki
Copy link
Collaborator

binki commented Apr 8, 2020

Hi @kinguru

This means that the default width of the image which BarcodeLib would try to generate is too skinny such that some bars which must be present could be invisible, preventing it from scanning. You can make it wider. The default value is 300, but maybe 500 would work. Maybe doing something like the following would work for a GUID?

var b = new BarcodeLib.Barcode();
using (var img = b.Encode(BarcodeLib.TYPE.CODE128, jobGUID.ToString(), 500, 150)) {
}

If you still get the same error, increase the number 500 more drastically. Perhaps 750. You will get a large image, but it should at least work at some point ;-).

@kinguru
Copy link
Author

kinguru commented Apr 8, 2020

The case is that I need minimum width barcode :) I know it is 420-450 px but could vary... As I understand there is no reason for you to limit it to some default value (300?) as you should already know the length of barcode generated.

@binki
Copy link
Collaborator

binki commented Apr 8, 2020

@kinguru I see. It looks like you should be able to do this with the Barcode.BarWidth property. Here is an example of using that property:

var barcode = new BarcodeLib.Barcode()
{
    // Use the minimum bar width of 1 pixel. Setting this causes
    // BarcodeLib to ignore the Width property and create the minimum-width
    // barcode.
    BarWidth = 1,
};
using var image = barcode.Encode(BarcodeLib.TYPE.CODE128, Guid.NewGuid().ToString());
using var outputStream = System.IO.File.OpenWrite("image.png");
image.Save(outputStream, System.Drawing.Imaging.ImageFormat.Png);

Some image widths I got were 607px, 541px, and 563px—seems like it is a variable width encoding ;-).

@barnhill
Copy link
Owner

this error is valid in that it lets you know you are trying to generate an image smaller than it can draw it. It cant draw bars less than 1 pixel so if it determines the width of the barcode wont hold the whole image when drawing 1px width bars ... it throws this. (As @binki alluded to)

@barnhill
Copy link
Owner

@binki Im gonna close this out unless you think we should leave this open?

@binki
Copy link
Collaborator

binki commented Jul 24, 2020

@barnhill It looks ready to be closed to me, please go ahead!

@barnhill
Copy link
Owner

Closing this as answered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants