Skip to content

Commit

Permalink
Merge pull request #191 from reportingissue/opaque-background
Browse files Browse the repository at this point in the history
Enable opaque backgrounds
  • Loading branch information
YipingRuan authored Sep 18, 2023
2 parents c6f675b + e4051a3 commit b3ff852
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 @@ -101,7 +101,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 b3ff852

Please sign in to comment.