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

png hexdata call ImageSharpImageConverter.ConvertImage retun transparent image with no content. #244

Open
masternan opened this issue May 27, 2024 · 8 comments

Comments

@masternan
Copy link

png hexdata call ImageSharpImageConverter.ConvertImage retun empty data.
and copy zpl code to https://labelary.com/, it display transparent image zone for png data.

snap1
snap2

@masternan
Copy link
Author

I modified ImageSharpImageConverter.ConvertImage like this,it is ok.

` public ImageResult ConvertImage(byte[] imageData)
{
using MemoryStream memoryStream = new MemoryStream();
using Image image = Image.Load(imageData);
using Image whiteBackgroundImage = new Image(image.Width, image.Height);
whiteBackgroundImage.Mutate(ctx => ctx.BackgroundColor(Color.White));
whiteBackgroundImage.Mutate(ctx => ctx.DrawImage(image, new Point(0, 0), 1.0f));
int num = ((whiteBackgroundImage.Width % 8 > 0) ? (whiteBackgroundImage.Width / 8 + 1) : (whiteBackgroundImage.Width / 8));
int binaryByteCount = whiteBackgroundImage.Height * num;
int num2 = 0;
int num3 = 0;
for (int i = 0; i < whiteBackgroundImage.Height; i++)
{
for (int j = 0; j < whiteBackgroundImage.Width; j++)
{
Rgba32 rgba = whiteBackgroundImage[j, i];
if ((rgba.R + rgba.G + rgba.B) / 3 < 128)
{
num2 |= 1 << 7 - num3;
}

         num3++;
         if (num3 == 8 || j == whiteBackgroundImage.Width - 1)
         {
             memoryStream.WriteByte((byte)num2);
             num2 = 0;
             num3 = 0;
         }
     }
 }
 return new ImageResult
 {
     RawData = memoryStream.ToArray(),
     BinaryByteCount = binaryByteCount,
     BytesPerRow = num
 };

}`

@primo-ppcg
Copy link
Collaborator

Unable to reproduce.

^XA
^FO32,128^GFA,2688,2688,28,:Z64:eNrtwTEBAAAAwqD+qWcLL6AAAOBnXV92Fw==:84a9
^FT245,180^A0N,50,50^FH\^FD#PartName#^FS
^XZ

image

@masternan
Copy link
Author

hotprocess.txt
Attach is the file exported from zebra designer,and i used DrawerOptions in the following code to analyze it.
Then i transfer it to konva object in order to edit it in web form with Konva.js.
At last I transfer the konva object to zpl, something goes wrong such as i describled.

private static DrawerOptions BuildDrawOption(string fontName = "NotoSansSC-SemiBold") { var fontFile = Path.Combine(AppContext.BaseDirectory, "fonts", $"{fontName}.ttf"); var drawOptions = new DrawerOptions { FontLoader = fontName => { return SKTypeface.FromFile(fontFile); }, OpaqueBackground=false, PdfOutput=false, RenderFormat = SKEncodedImageFormat.Png, RenderQuality = 100, Antialias=true, ReplaceDashWithEnDash = false }; return drawOptions; }

@primo-ppcg
Copy link
Collaborator

primo-ppcg commented May 28, 2024

The "hotprocess.txt" file contains two labels; I suspect you may only be exporting the first, which is blank and contains only directives.

The second label in the file renders correctly, according to what is show in Zebra Designer:
label

@masternan
Copy link
Author

masternan commented May 29, 2024

Thank you,but the case you described is not the reason.
When I modified ImageSharpImageConverter.ConvertImage function to add a whiteBackground to image label before analyzing it ,and it returns ok.

image

Attach is the exception before i modified the function, please refer it,thanks.

@primo-ppcg
Copy link
Collaborator

Please ensure that you are using SixLabors.ImageSharp v2.1.8 throughout your project. I suspect you may have a dependency conflict.

@masternan
Copy link
Author

masternan commented May 29, 2024

I use SixLabors.ImageSharp3.1.4 ,but when i modified the ImageSharpImageConverter.ConvertImage function,it returns ok.
so i think the problem was caused by the transparent png data.
Attatch is the right result after i modified the function.
image

@primo-ppcg primo-ppcg closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
@primo-ppcg
Copy link
Collaborator

Reopening this. Upgrading to ImageSharp 3.1.4 breaks rendering of GraphicField elements, and some barcodes. The project should be updated for forwards compatibility.

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

2 participants