Initial commit
Initial commit til Git. V2 er deployed
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
|
||||
namespace SixLabors.ImageSharp
|
||||
{
|
||||
public static class ImageSharpExtensions
|
||||
{
|
||||
public static byte[] ToSingleBitPixelByteArray(this Image<Rgba32> image, bool rasterFormat = true, int? maxWidth = null, int? maxHeight = null, float threshold = 0.5F)
|
||||
{
|
||||
image.Mutate(img =>
|
||||
{
|
||||
if (maxWidth.HasValue || maxHeight.HasValue)
|
||||
{
|
||||
img.Resize(new ResizeOptions
|
||||
{
|
||||
Mode = ResizeMode.Max,
|
||||
Size = new Size(maxWidth ?? int.MaxValue, maxHeight ?? int.MaxValue),
|
||||
});
|
||||
}
|
||||
|
||||
img.BackgroundColor(Color.White);
|
||||
img.Grayscale().BinaryDither(KnownDitherings.Stucki);
|
||||
|
||||
if (!rasterFormat)
|
||||
{
|
||||
img.Rotate(RotateMode.Rotate90);
|
||||
img.Flip(FlipMode.Horizontal);
|
||||
}
|
||||
});
|
||||
|
||||
var result = image.ToSingleBitPixelByteArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] ToSingleBitPixelByteArray(this Image<Rgba32> image)
|
||||
{
|
||||
var bytesPerRow = (image.Width + 7 & -8) / 8;
|
||||
|
||||
var result = new byte[bytesPerRow * image.Height];
|
||||
for (int y = 0; y < image.Height; y++)
|
||||
{
|
||||
var row = image.GetPixelRowSpan(y);
|
||||
var rowStartPosition = y * bytesPerRow;
|
||||
|
||||
for (int x = 0; x < row.Length; x++)
|
||||
{
|
||||
if (!row[x].IsBlack())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[rowStartPosition + (x / 8)] |= (byte)(0x01 << (7 - (x % 8)));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool IsBlack(this Rgba32 rgba)
|
||||
{
|
||||
return rgba.R == 0 && rgba.G == 0 && rgba.B == 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ESCPOS_NET.Extensions
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
public static void LogExceptions(this Task task)
|
||||
{
|
||||
task.ContinueWith(t =>
|
||||
{
|
||||
var aggException = t.Exception.Flatten();
|
||||
foreach (var exception in aggException.InnerExceptions)
|
||||
{
|
||||
Logging.Logger?.LogError(exception, "Uncaught Thread Exception.");
|
||||
}
|
||||
},
|
||||
TaskContinuationOptions.OnlyOnFaulted);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
PointOfSale/Utilities/ESCPOS_NET/Extensions/Util.cs
Normal file
36
PointOfSale/Utilities/ESCPOS_NET/Extensions/Util.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ESCPOS_NET.Extensions
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds to the list of T items and/or enumerables of T. All other types will be ignored and not added to the list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">List's items type.</typeparam>
|
||||
/// <param name="list">List to be added the items.</param>
|
||||
/// <param name="items">Items to be added.</param>
|
||||
/// <returns>True if no item was ignored, otherwise False.</returns>
|
||||
public static bool AddRange<T>(this List<T> list, params object[] items)
|
||||
{
|
||||
bool ignoredItems = false;
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item is T itemT)
|
||||
{
|
||||
list.Add(itemT);
|
||||
}
|
||||
else if (item is IEnumerable<T> arrayT)
|
||||
{
|
||||
list.AddRange(arrayT);
|
||||
}
|
||||
else
|
||||
{
|
||||
ignoredItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
return !ignoredItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user