You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.3 KiB

using BarcodeLib.UI;
using DataMatrix.net;
using DatamatrixNF;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace BarcodeLib
{
public class Barcode
{
public System.Drawing.Image Get_LinerBarcode(Barcoded.Symbology Typ, string Inhalt, string HrText,string HrPosition, string HrFont, int HrSize, int Rotation)
{
Barcoded.LinearBarcode newbarcode = new Barcoded.LinearBarcode(HrText, Typ);
if (HrText != "")
{
newbarcode.Encoder.HumanReadableValue = HrText;
newbarcode.Encoder.SetHumanReadablePosition(HrPosition);
newbarcode.Encoder.SetHumanReadableFont(HrFont, HrSize);
}
switch (Rotation)
{
case 0: break;
case 90: newbarcode.Rotate(newbarcode.Image, Rotation); break;
case 180: newbarcode.Rotate(newbarcode.Image, Rotation); break;
case 270: newbarcode.Rotate(newbarcode.Image, Rotation); break;
}
return newbarcode.Image;
}
public String Get_LinerBarcodeAsBase64(Barcoded.Symbology Typ, string Inhalt, string HrText, string HrPosition, string HrFont, int HrSize, int Rotation)
{
System.Drawing.Image timg;
timg = Get_LinerBarcode(Typ, Inhalt, HrText, HrPosition, HrFont,HrSize, Rotation);
using (MemoryStream m = new MemoryStream())
{
timg.Save(m, timg.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
m.Dispose();
timg.Dispose();
return base64String;
}
}
public System.Drawing.Image Get_Datamatrix(DmtxScheme Typ, string InHalt, int ModuleSize, int Marigin,int Rotation, String TextPlacement, string HrText, string HrFontName, int HrFontSize)
{
DmtxScheme dmtxScheme = new DmtxScheme();
DmtxImageEncoder encoder = new DmtxImageEncoder();
DmtxImageEncoderOptions options = new DmtxImageEncoderOptions();
options.ModuleSize = ModuleSize;
options.MarginSize = Marigin;
options.BackColor = Color.White;
options.ForeColor = Color.Black;
options.Scheme = Typ;
Bitmap encodedBitmap1 = encoder.EncodeImage(InHalt, options);
if (HrText != "") {
DatamatrixTextAddtion dta = new DatamatrixTextAddtion();
int textpos = 0;
if (TextPlacement == "Right") { textpos = 0; } else { textpos = 1; }
encodedBitmap1 = dta.UpdateText(encodedBitmap1, textpos, HrText, HrFontName, HrFontSize,Marigin, Rotation);
}
return encodedBitmap1;
}
public string Get_DatamatrixAsBase64(DmtxScheme Typ, string InHalt, int ModuleSize, int Marigin, int Rotation, String TextPlacement, string HrText, string HrFontName, int HrFontSize)
{
System.Drawing.Image timg;
timg = Get_Datamatrix(Typ,InHalt,ModuleSize, Marigin, Rotation, TextPlacement, HrText,HrFontName, HrFontSize);
using (MemoryStream m = new MemoryStream())
{
timg.Save(m, timg.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
m.Dispose();
timg.Dispose();
return base64String;
}
}
public System.Drawing.Image Get_QRCode(String Typ, string Inhalt)
{
Barcoded.qr.qrcode qr = new Barcoded.qr.qrcode(Typ, Inhalt);
return qr.RenderCode();
}
public string Get_QRCodeAsBase64(string Typ, string Inhalt)
{
System.Drawing.Image timg;
timg = Get_QRCode(Typ, Inhalt);
using (MemoryStream m = new MemoryStream())
{
timg.Save(m, timg.RawFormat);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
m.Dispose();
timg.Dispose();
return base64String;
}
}
public System.Drawing.Image ScaleImg(System.Drawing.Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(newImage))
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
return newImage;
}
public void Gen_BCK(string connectionstring)
{
Barcodekleber bck = new Barcodekleber(connectionstring);
bck.Show();
}
}
}