-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElasticLabelExtensions.cs
More file actions
78 lines (58 loc) · 2.74 KB
/
ElasticLabelExtensions.cs
File metadata and controls
78 lines (58 loc) · 2.74 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
using System.Drawing;
using System.Drawing.Imaging;
namespace SolidMatrix.ElasticLabels;
public static class ElasticLabelExtensions
{
public static Image RenderPreview(this ElasticLabel label)
{
var dst = new Bitmap(label.Width, label.Height, PixelFormat.Format24bppRgb);
using var g = Graphics.FromImage(dst);
RenderPreviewOnGraphics(label, g, label.Width, label.Height);
dst.SetResolution(label.Width / label.WidthCm * 2.54f, label.Height / label.HeightCm * 2.54f);
return dst;
}
public static Image Render(this ElasticLabel label, IDictionary<string, string> slotValues)
{
var dst = new Bitmap(label.Width, label.Height, PixelFormat.Format24bppRgb);
using var g = Graphics.FromImage(dst);
RenderOnGraphics(label, g, label.Width, label.Height, slotValues);
dst.SetResolution(label.Width / label.WidthCm * 2.54f, label.Height / label.HeightCm * 2.54f);
return dst;
}
public static void RenderPreviewOnGraphics(this ElasticLabel label, Graphics g, int width, int height)
{
ElasticLabel.RenderPreviewOnGraphics(label, g, width, height);
}
public static void RenderOnGraphics(this ElasticLabel label, Graphics g, int width, int height, IDictionary<string, string> slotValues)
{
ElasticLabel.RenderOnGraphics(label, g, width, height, slotValues);
}
public static byte[] Encode(this ElasticLabel label)
{
return ElasticLabel.Encode(label);
}
public static void Save(this ElasticLabel label, string path)
{
ElasticLabel.Save(label, path);
}
public static string? GetAttributeValue(this ElasticLabel label, string entry)
{
return label.Fields.Where(field => field.Type == ElasticFieldType.Attribute && field.Entry == entry).FirstOrDefault()?.Value;
}
public static string[] GetAttributeEntries(this ElasticLabel label)
{
return [.. label.Fields.Where(field => field.Type == ElasticFieldType.Attribute).Select(field => field.Entry)];
}
public static string[] GetTextSlotEntries(this ElasticLabel label)
{
return [.. label.Fields.Where(field => field.Type == ElasticFieldType.TextSlot).Select(field => field.Entry)];
}
public static string[] GetQrCodeSlotEntries(this ElasticLabel label)
{
return [.. label.Fields.Where(field => field.Type == ElasticFieldType.QrCodeSlot).Select(field => field.Entry)];
}
public static string[] GetSlotEntries(this ElasticLabel label)
{
return [.. label.Fields.Where(field => field.Type == ElasticFieldType.TextSlot || field.Type == ElasticFieldType.QrCodeSlot).Select(field => field.Entry)];
}
}