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.
145 lines
5.8 KiB
145 lines
5.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security.AccessControl;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace DatamatrixNF
|
|
{
|
|
public class DatamatrixTextAddtion
|
|
{
|
|
Color FontColor = Color.Black;
|
|
Color BackColor = Color.White;
|
|
string Fontname = "Arial";
|
|
int FontSize = 12;
|
|
int Height = 0;
|
|
int Width = 0;
|
|
public Bitmap UpdateText(Bitmap img, int format, string text, string fontname, int fontsize, int margin, int rotation)
|
|
{
|
|
Color FontColor = Color.Black;
|
|
Color BackColor = Color.White;
|
|
string FontName = fontname;
|
|
int FontSize = fontsize;
|
|
int Height = 0;
|
|
int Width = 0;
|
|
var objFont = new Font(FontName, FontSize);
|
|
var image1bmp = new Bitmap(400, 400);
|
|
Bitmap image1 = img;
|
|
Graphics objFontsize = Graphics.FromImage(image1bmp);
|
|
var sf = objFontsize.MeasureString(text, objFont);
|
|
switch (format)
|
|
{
|
|
case 0:
|
|
case 2:
|
|
{
|
|
if (image1.Width < 70)
|
|
Width = Convert.ToInt32(sf.Width) + 10 + image1.Width;
|
|
else
|
|
Width = image1.Width * 3;
|
|
break;
|
|
}
|
|
case 1:
|
|
case 3:
|
|
{
|
|
if (image1.Width < 70)
|
|
Width = Convert.ToInt32(sf.Width) + 10 + image1.Width;
|
|
else
|
|
Width = image1.Width * 3;
|
|
break;
|
|
}
|
|
case 22:
|
|
{
|
|
if (image1.Height < 70)
|
|
Height = Convert.ToInt32(sf.Height) + 10 + image1.Height;
|
|
else
|
|
Height = image1.Height * 3;
|
|
break;
|
|
}
|
|
case 33:
|
|
{
|
|
if (image1.Height < 70)
|
|
Height = Convert.ToInt32(sf.Height) + 10 + image1.Height;
|
|
else
|
|
Height = image1.Height * 3;
|
|
break;
|
|
}
|
|
}
|
|
Height = image1.Height;
|
|
Bitmap objBitmap = new Bitmap(Width, Height);
|
|
Graphics objGraphics = Graphics.FromImage(objBitmap);
|
|
var objBrushForeColor = new SolidBrush(FontColor);
|
|
var objBrushBackColor = new SolidBrush(BackColor);
|
|
Color objColor;
|
|
|
|
switch (format)
|
|
{
|
|
case 0: // rechts
|
|
{
|
|
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
|
|
objGraphics.DrawImage(image1, new System.Drawing.Point(0, 0));
|
|
Width = image1.Width + 20;
|
|
Height = (int)image1.Height - (int)sf.Height - margin;
|
|
var objPoint = new System.Drawing.Point(Width, Height);
|
|
objGraphics.DrawString(text, objFont, objBrushForeColor, objPoint);
|
|
break;
|
|
}
|
|
case 1: // links
|
|
{
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
|
|
objGraphics.DrawImage(image1, new System.Drawing.Point(Width - (int)image1.Width - margin, 0));
|
|
|
|
Width = margin + 20;
|
|
|
|
Height = (int)image1.Height - (int)sf.Height - margin;
|
|
var objPoint = new System.Drawing.Point(Width, Height);
|
|
objGraphics.DrawString(text, objFont, objBrushForeColor, objPoint);
|
|
break;
|
|
}
|
|
case 2: // links
|
|
{
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
|
|
var objPoint = new PointF(image1.Width + 10, Height - sf.Height - 0);
|
|
objGraphics.DrawString(text, objFont, objBrushForeColor, objPoint);
|
|
objGraphics.DrawImage(image1, new System.Drawing.Point(0, 0));
|
|
objBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
var stringFormat = new StringFormat();
|
|
stringFormat.Alignment = StringAlignment.Far;
|
|
stringFormat.LineAlignment = StringAlignment.Near;
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height);
|
|
var objPoint = new PointF(Width - image1.Width - 10, Height - sf.Height - 0);
|
|
objGraphics.DrawString(text, objFont, objBrushForeColor, objPoint, stringFormat);
|
|
objGraphics.DrawImage(image1, new System.Drawing.Point(Width - image1.Width, 0));
|
|
objBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
|
|
break;
|
|
}
|
|
case var @case when @case == 3:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
image1 = null;
|
|
|
|
switch (rotation)
|
|
{
|
|
case 90: { objBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone); break; }
|
|
case 180:{ objBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone); break; }
|
|
case 270:{ objBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone); break; }
|
|
}
|
|
|
|
return objBitmap;
|
|
|
|
}
|
|
|
|
}
|
|
}
|