Skip to content

Commit

Permalink
add opaque option to drawer properties + add background code
Browse files Browse the repository at this point in the history
  • Loading branch information
Reporting Issue committed Sep 15, 2023
1 parent 6434c62 commit e4051a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/BinaryKits.Zpl.Viewer/ElementDrawers/DrawerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public class DrawerOptions

public SKEncodedImageFormat RenderFormat { get; set; } = SKEncodedImageFormat.Png;

/// <summary>
/// Applies label over a white background after rendering all elements
/// </summary>
public bool OpaqueBackground { get; set; } = false;

public int RenderQuality { get; set; } = 80;

public bool ReplaceDashWithEnDash { get; set; } = true;
Expand Down
21 changes: 20 additions & 1 deletion src/BinaryKits.Zpl.Viewer/ZplElementDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,26 @@ public byte[] Draw(
}
}

using var data = skBitmap.Encode(_drawerOptions.RenderFormat, _drawerOptions.RenderQuality);
SKBitmap finalBitmap;
if (this._drawerOptions.OpaqueBackground == true)
{
finalBitmap = new SKBitmap(labelImageWidth, labelImageHeight);
using (SKCanvas canvas = new SKCanvas(finalBitmap))
{
SKPaint paint = new SKPaint
{
IsAntialias = true,
FilterQuality = SKFilterQuality.High
};
canvas.Clear(SKColors.White);
canvas.DrawBitmap(skBitmap, 0, 0, paint);
}
}
else {
finalBitmap = skBitmap;
}

using var data = finalBitmap.Encode(_drawerOptions.RenderFormat, _drawerOptions.RenderQuality);
return data.ToArray();
}

Expand Down

0 comments on commit e4051a3

Please sign in to comment.