-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cs
More file actions
98 lines (81 loc) · 3.42 KB
/
utils.cs
File metadata and controls
98 lines (81 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Neodynamic.SDK.BarcodeCore;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Security.Policy;
namespace QRCode
{
public static class Utils
{
/// <summary>
/// Codifica una stringa e la converte in un file immagine sul disco
/// </summary>
/// <param name="code">codice da tradurre in qrcode</param>
/// <param name="fileImage">percorso completo del file qr da salvare</param>
public static Image CreateImage(string code, string fileImage = @"C\TEMP\qrcode.png", bool savetodisk = false)
{
string cwd = Directory.GetCurrentDirectory();
Image _retImage = Image.FromFile(cwd + "/Pictures/blankCode.bmp"); //immagine di default se non viene inserito nulla
try
{
//Create an instance of BarcodeProfessional class
using (BarcodeProfessional bc = new BarcodeProfessional())
{
//Set the desired barcode type or symbology
bc.Symbology = Symbology.QRCode;
//Set value to encode
bc.Code = code;
//Generate barcode image and get buffer
byte[] barcodeBuffer = bc.GetBarcodeImage(SKEncodedImageFormat.Png, 800);
if (savetodisk)
{ //salvo sul disco
bc.Save(fileImage, SKEncodedImageFormat.Png);
}
using (var ms = new MemoryStream(barcodeBuffer))
{
_retImage = Image.FromStream(ms);
}
}
}
catch (Exception ex)
{
Global.LoggerFrm.LoggerAddItem(ex.Message);
}
return _retImage;
}
/// <summary>
/// Resize the image to the specified width and height.
/// </summary>
/// <param name="image">The image to resize.</param>
/// <param name="width">The width to resize to.</param>
/// <param name="height">The height to resize to.</param>
/// <returns>The resized image.</returns>
public static Bitmap ResizeImage(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}
}
}