Skip to content

Commit ed25a4b

Browse files
authored
Merge pull request #32 from Helius01/master
feat : Save image file as async
2 parents 380744c + b5bde8a commit ed25a4b

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

NetBarcode/Barcode.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using NetBarcode.Types;
2-
using System;
1+
using System;
32
using System.IO;
43
using System.Linq;
4+
using System.Threading.Tasks;
5+
using NetBarcode.Types;
56
using SixLabors.Fonts;
6-
using SixLabors.ImageSharp.PixelFormats;
7-
using SixLabors.ImageSharp.Processing;
87
using SixLabors.ImageSharp;
98
using SixLabors.ImageSharp.Drawing.Processing;
109
using SixLabors.ImageSharp.Formats;
@@ -16,6 +15,8 @@
1615
using SixLabors.ImageSharp.Formats.Tga;
1716
using SixLabors.ImageSharp.Formats.Tiff;
1817
using SixLabors.ImageSharp.Formats.Webp;
18+
using SixLabors.ImageSharp.PixelFormats;
19+
using SixLabors.ImageSharp.Processing;
1920

2021
namespace NetBarcode
2122
{
@@ -496,6 +497,17 @@ public void SaveImageFile(string path, ImageFormat imageFormat = ImageFormat.Jpe
496497
image.Save(path, getImageEncoder(imageFormat));
497498
}
498499

500+
/// <summary>
501+
/// Saves the image to a file async.
502+
/// </summary>
503+
/// <param name="path">The file path for the image.</param>
504+
/// <param name="imageFormat">The image format. Defaults to Jpeg.</param>
505+
public async Task SaveImageFileAsync(string path, ImageFormat imageFormat = ImageFormat.Jpeg)
506+
{
507+
using (var image = GenerateImage())
508+
await image.SaveAsync(path, getImageEncoder(imageFormat));
509+
}
510+
499511
/// <summary>
500512
/// Gets the image in PNG format as a Base64 encoded string.
501513
/// </summary>
@@ -686,7 +698,7 @@ private Image GenerateImage()
686698
{
687699
var labelY = 0;
688700
var labelX = 0;
689-
701+
690702
switch (_labelPosition)
691703
{
692704
case LabelPosition.TopCenter:
@@ -711,7 +723,7 @@ private Image GenerateImage()
711723

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

714-
image.Mutate(x=> x.DrawText(labelTextOptions, _data, _foregroundColor));
726+
image.Mutate(x => x.DrawText(labelTextOptions, _data, _foregroundColor));
715727
}
716728

717729
return image;

0 commit comments

Comments
 (0)