1
- using NetBarcode . Types ;
2
- using System ;
1
+ using System ;
3
2
using System . IO ;
4
3
using System . Linq ;
4
+ using System . Threading . Tasks ;
5
+ using NetBarcode . Types ;
5
6
using SixLabors . Fonts ;
6
- using SixLabors . ImageSharp . PixelFormats ;
7
- using SixLabors . ImageSharp . Processing ;
8
7
using SixLabors . ImageSharp ;
9
8
using SixLabors . ImageSharp . Drawing . Processing ;
10
9
using SixLabors . ImageSharp . Formats ;
16
15
using SixLabors . ImageSharp . Formats . Tga ;
17
16
using SixLabors . ImageSharp . Formats . Tiff ;
18
17
using SixLabors . ImageSharp . Formats . Webp ;
18
+ using SixLabors . ImageSharp . PixelFormats ;
19
+ using SixLabors . ImageSharp . Processing ;
19
20
20
21
namespace NetBarcode
21
22
{
@@ -496,6 +497,17 @@ public void SaveImageFile(string path, ImageFormat imageFormat = ImageFormat.Jpe
496
497
image . Save ( path , getImageEncoder ( imageFormat ) ) ;
497
498
}
498
499
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
+
499
511
/// <summary>
500
512
/// Gets the image in PNG format as a Base64 encoded string.
501
513
/// </summary>
@@ -686,7 +698,7 @@ private Image GenerateImage()
686
698
{
687
699
var labelY = 0 ;
688
700
var labelX = 0 ;
689
-
701
+
690
702
switch ( _labelPosition )
691
703
{
692
704
case LabelPosition . TopCenter :
@@ -711,7 +723,7 @@ private Image GenerateImage()
711
723
712
724
labelTextOptions . Origin = new Point ( labelX , labelY ) ;
713
725
714
- image . Mutate ( x=> x . DrawText ( labelTextOptions , _data , _foregroundColor ) ) ;
726
+ image . Mutate ( x => x . DrawText ( labelTextOptions , _data , _foregroundColor ) ) ;
715
727
}
716
728
717
729
return image ;
0 commit comments