Skip to content

Commit

Permalink
Merge pull request #32 from Helius01/master
Browse files Browse the repository at this point in the history
feat : Save image file as async
  • Loading branch information
Tagliatti authored Jun 20, 2022
2 parents 380744c + b5bde8a commit ed25a4b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions NetBarcode/Barcode.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using NetBarcode.Types;
using System;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NetBarcode.Types;
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.Formats;
Expand All @@ -16,6 +15,8 @@
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

namespace NetBarcode
{
Expand Down Expand Up @@ -496,6 +497,17 @@ public void SaveImageFile(string path, ImageFormat imageFormat = ImageFormat.Jpe
image.Save(path, getImageEncoder(imageFormat));
}

/// <summary>
/// Saves the image to a file async.
/// </summary>
/// <param name="path">The file path for the image.</param>
/// <param name="imageFormat">The image format. Defaults to Jpeg.</param>
public async Task SaveImageFileAsync(string path, ImageFormat imageFormat = ImageFormat.Jpeg)
{
using (var image = GenerateImage())
await image.SaveAsync(path, getImageEncoder(imageFormat));
}

/// <summary>
/// Gets the image in PNG format as a Base64 encoded string.
/// </summary>
Expand Down Expand Up @@ -686,7 +698,7 @@ private Image GenerateImage()
{
var labelY = 0;
var labelX = 0;

switch (_labelPosition)
{
case LabelPosition.TopCenter:
Expand All @@ -711,7 +723,7 @@ private Image GenerateImage()

labelTextOptions.Origin = new Point(labelX, labelY);

image.Mutate(x=> x.DrawText(labelTextOptions, _data, _foregroundColor));
image.Mutate(x => x.DrawText(labelTextOptions, _data, _foregroundColor));
}

return image;
Expand Down

0 comments on commit ed25a4b

Please sign in to comment.