tagliatti / netbarcode Goto Github PK
View Code? Open in Web Editor NEWBarcode generation library written in C# and .NET Standard 2
License: MIT License
Barcode generation library written in C# and .NET Standard 2
License: MIT License
Expose the LabelFont as a property so that it can be changed as necessary. For example, when generating larger than normal barcodes we'll want to also have a larger than normal font to match.
Hi,
I'm trying to create a barcode specifying the width and height, but when I'm doing that It's not possible to specify the code type, could you add a new constructor with those parameters?
Thanks.
Hi,
when I try to generate a Codabar with C letter, but when I Scan the code I read letter B instead of C
Example:
var barcode = new Barcode("C123456789C", NetBarcode.Type.Codabar, true, width, height);
barcodeImage = barcode.GetBase64Image();
when I view the image in a tag with embded data I view in the image data C123456789C, but when I scan the barcode the result is B123456789B
So I try to invert the code with:
var barcode = new Barcode("B123456789B", NetBarcode.Type.Codabar, true, width, height);
barcodeImage = barcode.GetBase64Image();
and now when I scan the barcode the result is C123456789C
Hi,
Below code does not save image nor returning any exception:
Dim barcode = New Barcode("123456789", TYPE.CODE128)
barcode.SaveImage("test.png", SaveTypes.PNG)
Using NetBarcode 1.4.0 installed via NuGet
Also Looks like docs are not up to date, barcode.SaveImageFile
does not exist.
Regards,
I'm doing this:
var barcode = new Barcode(barcodeData, Type.Code39, false, 321, 38);
The application is running in a Linux container with no fonts installed so the SystemFonts.Collection.Families
collection is empty.
Because of this it crashes with a "Sequence contains no elements" error in Barcode.cs on line 79.
It would be nice if it only checked the fonts when showLabel
is set to true
, as otherwise the font is not used.
Could replace First with FirstOrDefault and then crash if font is null before rendering the label?
Is there any way to diagnose Unmanaged memory leak ?
I am using .NET 5.0 Console App with NetCode. The program it self is simple it calls barcode library & creates a base64string from Image 5000 times, I am using 'using blocks' therefore disposing is also being handled.
static void Main(string[] args)
{
Console.ReadKey();
for (int i = 0; i < 5000; i++)
{
Barcode bar = new Barcode("123456789123456", Type.Code128);
using (var image = bar.GetImage())
{
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms,ImageFormat.Png);
var base64 = Convert.ToBase64String(ms.ToArray());
Console.WriteLine(i);
}
}
}
Console.ReadKey();
Console.ReadKey();
}
On windows this program consumes 15-25 MB (doesn't go above that) but on Linux Unmanaged memory constantly increases with each iteration but never goes down at all (goes upto 600MB on 5000 iterations).
Linux dotMemory:
Windows dotMemory:
I have tried the same program after fixing the Font, FontFamily disposing issue but the results are same.
I am using docker with:
FROM mcr.microsoft.com/dotnet/aspnet:5.0.15-focal as base
FROM mcr.microsoft.com/dotnet/sdk:5.0.406-focal AS build
Whole demo with dockerfile & dotmemory snapshots can be found here.
Hi, in my work we are using QuestPdf, which has a Skia Canvas API to draw on the PDF file.
I think it would be useful to have an adapter to generate the Skia Canvas from the binary string generated from IBarcode.GetEncoding()
, maybe NetBarcode.Skia :) But I am not sure whether I should create a PR for it or does SkiaSharp is worth a separate adapter at all.
I made a dirty prototype here:
For now, it's just for exploration with fixed-size canvas, but if you are okay I am willing to make a PR.
Let me know what you think. Thank you!
While they are working for scan readers, the barcodes generated for EAN codes don't comply with the industry standard representation (with longer bars where the markers are, and "broken" label - see https://en.wikipedia.org/wiki/International_Article_Number#/media/File:EAN13.svg for an example).
I appreciate the elegance of your solution for rendering the barcode, and as I said there is no practical or functional necessity to improve the rendering, but it would be cool to obtain an image that is 100% similar to what you would find on a commercial product package.
I offer to implement a better rendering for EAN-8 and EAN-13 through polymorphism. Is this something you would be interested in adding, or would you rather keep it simpler in your library?
The lib was completely remodeled for version 2. It is fully functional, I left it in beta to gather feedbacks.
I invite you to test it and send your feedback on what you think of the changes.
Branch: https://github.com/Tagliatti/NetBarcode/tree/v2
Nuget: https://www.nuget.org/packages/NetBarcode/2.0.0-beta.1
Hi @Tagliatti, first of all, thank you for your library!
I have been using the library for some time, namely for Code128C. I encountered a problem with versions 1.5+, which I already wrote about (Issue #29).
var barcode = new Barcode("660004005000080000221020220529113509", NetBarcode.Type.Code128C, false, 466, 40);
barcode.SaveImageFile(@"C:\Temp\barcode.png", ImageFormat.Png);
Result for version 1.4.5
Result for version 1.6.0
In the latest version barcode lines are rendered as thicker and when I use barcode.GetBase64Image();
the barcode is really corrupted.
I tried to figure out the cause of the problem and found that the problem is in this part of the code:
imageContext.DrawLines(drawingOptions, pen,
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, _height - labelHeight)
);
The problem is with ImageSharp method DrawLines. This method will not draw a line in the form of a solid rectangle if the pen width is equal to or greater than 2 :-(
I suggest using the method FillPolygon, and the corresponding code would look like this:
imageContext.FillPolygon(drawingOptions, _foregroundColor,
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth + iBarWidth / iBarWidthModifier, 0),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth + iBarWidth / iBarWidthModifier, _height - labelHeight),
new PointF(pos * iBarWidth + shiftAdjustment + halfBarWidth, _height - labelHeight));
The variable pen is no longer needed.
And result for modified version 1.6.0 is the same as the one generated by the library version 1.4.5!
What do you think? Wouldn't it work better this way?
Hi,
I am trying to figure out how can I set widths of bars (wide and thin) and based on that, to calculate what width barcode will be. As I unerstand, now barcodes are scaled to desired width. What I need is to have fixed bars width and variable width of generated image.
Thanks in advance.
Hi,
I'm trying to use this library with .NET 6 on a docker alpine image. However I'm running into this issue. Are there plans of swapping out the System.Drawing
dependencies for one of the recommended libraries?
Thanks!
When generating barcodes for ASP.NET Core, we need them as a Byte[] so that we can wrap them in a file content result. For example:
public FileContentResult Code128(string barcode)
{
var bc = new NetBarcode.Barcode(barcode, true);
var result = Convert.FromBase64String(bc.GetBase64Image());
Stream stream = new MemoryStream(result);
return new FileContentResult(result, "image/png");
}
Currently the way this is done is by asking Barcode
to concert the image into a Byte[] which is then turned into a Base64 string, after which we turn it back into a Byte[],
This new method would just omit the Base64 step.
In this version it was Replaced System.Drawing by ImageSharp, comment if you find any problems.
Thanks
I really like this feature, but am using a mac and getting the error below :
System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libgdiplus': The specified module could not be found.
at System.Runtime.InteropServices.FunctionWrapper`1.get_Delegate()
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip..cctor()
--- End of inner exception stack trace ---
at System.Drawing.SafeNativeMethods.Gdip.GdipGetGenericFontFamilySansSerif(IntPtr& fontfamily)
at System.Drawing.FontFamily.GetGdipGenericSansSerif()
at System.Drawing.FontFamily.get_GenericSansSerif()
at System.Drawing.Font.CreateFont(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical)
at NetBarcode.Barcode..ctor(String data)
at ICFERApp.Controllers.StudentController.Details(Int64 id) in /Users/idrislutaaya/RiderProjects/ICFERApp/ICFERApp/Controllers/StudentController.cs:line 176
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
I also tried to install libgdiplus
with this brew install mono-libgdiplus
command , but it didn't workout. What caused this issue ?
I am trying to generate an image using the NetBarcode library.
However I get a ArgumentNullException.
My code looks like this:
var bc = new NetBarcode.Barcode(code, NetBarcode.Type.EAN13, true);
var b64 = bc.GetBase64Image();
Am I doing something wrong, or is there an error in the library?
I am running this in Blazor (server side). .NET version 7.0
Thanks in advance!
System.NullReferenceException: Object reference not set to an instance of an object.
at NetBarcode.Types.EAN13.GetEncoding()} | System.NullReferenceException
CODE:
var barcode = new Barcode(newStringValue, TypeNet.EAN13, true); <--- Exception origen
use implement
using NetBarcode;
using TypeNet = NetBarcode.Type;
Ambient:
Ubuntu 20.04
NetCore 3.1
I use an online generator and decrypt through an online reader and everything is correct.
But when I use this package, 0 is added to the beginning of the string when decrypting.
To repeat my case, you need to use Code128 and generate the string "765256359354976758112".
Version 1.7.0
Netstandard 2.0 Error generate ๐
"Could not load file or assembly 'NetBarcode, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified."
this error I get when trying to consume the library class installed or referenced in a NetCore 2.0 project !!!
Good morning, please I would like to note that I can't find a way to generate a check digit to add it to the database and the label.
I tried 123456789012 as a barcode and when displaying the label I only get the 12 digits without the check digit included.
Please, can you add a method to get it or include it directly in the label.
THANKS IN ADVANCE.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.