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.
154 lines
7.1 KiB
154 lines
7.1 KiB
Imports System.Drawing
|
|
Imports System.Net
|
|
Imports Model
|
|
Public Class MW6Datamatrix
|
|
|
|
Dim ObjPointMinus As Integer = 0
|
|
Public Sub Generage_BarcodeImage(ByRef docdata As clsDocData, temppath As String)
|
|
Dim FontColor As Color = Color.Black
|
|
Dim BackColor As Color = Color.White
|
|
Dim FontName As String = docdata.Zusatz_Font
|
|
Dim FontSize As Integer = docdata.Zusatz_FontSize
|
|
Dim Height As Integer = 0
|
|
Dim Width As Integer = 0
|
|
Dim objFont As New Drawing.Font(FontName, FontSize)
|
|
Dim image1bmp As New Bitmap(400, 400)
|
|
Dim image1 As Bitmap = Datamatrix_Generator_1(Height, Width, docdata)
|
|
Dim objFontsize As Graphics = Graphics.FromImage(image1bmp)
|
|
Dim sf = objFontsize.MeasureString(docdata.barcode_text, objFont)
|
|
Select Case docdata.barcode_formatn
|
|
Case 0, 2
|
|
If image1.Width < 70 Then Width = sf.Width + 10 + image1.Width Else Width = image1.Width * 3
|
|
Case 1, 3
|
|
If image1.Width < 70 Then Width = sf.Width + 10 + image1.Width Else Width = image1.Width * 3
|
|
Case 22
|
|
If image1.Height < 70 Then Height = sf.Height + 10 + image1.Height Else Height = image1.Height * 3
|
|
Case 33
|
|
If image1.Height < 70 Then Height = sf.Height + 10 + image1.Height Else Height = image1.Height * 3
|
|
End Select
|
|
|
|
Dim objBitmap As New Bitmap(Width, Height)
|
|
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
|
|
Dim objBrushForeColor As New SolidBrush(FontColor)
|
|
Dim objBrushBackColor As New SolidBrush(BackColor)
|
|
Dim objColor As Color
|
|
|
|
Select Case docdata.barcode_formatn
|
|
Case 0 'rechts
|
|
Dim stringFormat As New StringFormat()
|
|
stringFormat.Alignment = StringAlignment.Far
|
|
stringFormat.LineAlignment = StringAlignment.Near
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
|
|
Dim objPoint As New PointF(Width - image1.Width - 10, Height - sf.Height - ObjPointMinus)
|
|
objGraphics.DrawString(docdata.barcode_text, objFont, objBrushForeColor, objPoint, stringFormat)
|
|
objGraphics.DrawImage(image1, New Drawing.Point(Width - image1.Width, 0))
|
|
Case 1 'links
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
|
|
Dim objPoint As New PointF(image1.Width + 10, Height - sf.Height - ObjPointMinus)
|
|
objGraphics.DrawString(docdata.barcode_text, objFont, objBrushForeColor, objPoint)
|
|
objGraphics.DrawImage(image1, New Drawing.Point(0, 0))
|
|
Case 2 'links
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
|
|
Dim objPoint As New PointF(image1.Width + 10, Height - sf.Height - ObjPointMinus)
|
|
objGraphics.DrawString(docdata.barcode_text, objFont, objBrushForeColor, objPoint)
|
|
objGraphics.DrawImage(image1, New Drawing.Point(0, 0))
|
|
objBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone)
|
|
Case 3
|
|
Dim stringFormat As New StringFormat()
|
|
stringFormat.Alignment = StringAlignment.Far
|
|
stringFormat.LineAlignment = StringAlignment.Near
|
|
objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
|
|
Dim objPoint As New PointF(Width - image1.Width - 10, Height - sf.Height - ObjPointMinus)
|
|
objGraphics.DrawString(docdata.barcode_text, objFont, objBrushForeColor, objPoint, stringFormat)
|
|
objGraphics.DrawImage(image1, New Drawing.Point(Width - image1.Width, 0))
|
|
objBitmap.RotateFlip(RotateFlipType.Rotate90FlipNone)
|
|
Case 3
|
|
End Select
|
|
image1 = Nothing
|
|
objBitmap.Save(temppath + "a_" + docdata.Dokumentid + ".png", System.Drawing.Imaging.ImageFormat.Png)
|
|
objBitmap = Nothing
|
|
End Sub
|
|
|
|
Public Function Datamatrix_Generator_1(ByRef Height As Integer, ByRef width As Integer, ByRef docdata As clsDocData) As Image
|
|
Dim DMNetCtrl As New MW6.SDK.DataMatrix.DataMatrixNet
|
|
DMNetCtrl.Data = docdata.barcode_content
|
|
Dim ActualRows As Integer
|
|
Dim ActualCols As Integer
|
|
Dim ActualWidth As Integer
|
|
Dim ActualHeight As Integer
|
|
Dim ExtraWidth As Integer = 0
|
|
Dim ExtraHeight As Integer = 0
|
|
Dim imgsize As Integer
|
|
DMNetCtrl.GetActualRC(ActualRows, ActualCols)
|
|
DMNetCtrl.GetActualSize(True, Nothing, ActualWidth, ActualHeight)
|
|
DMNetCtrl.SetSize(ActualWidth + ExtraWidth, ActualHeight + ExtraHeight)
|
|
Dim MS As System.IO.MemoryStream = New System.IO.MemoryStream
|
|
DMNetCtrl.SaveAsMemory(MS, System.Drawing.Imaging.ImageFormat.Png)
|
|
Dim img4 As Image
|
|
img4 = System.Drawing.Image.FromStream(MS)
|
|
If docdata.barcode_kantenlaenge = "" Then docdata.barcode_kantenlaenge = 2
|
|
|
|
Try
|
|
imgsize = docdata.barcode_kantenlaenge * 37.795275593333
|
|
Catch
|
|
imgsize = 1.5 * 37.795275593333
|
|
End Try
|
|
|
|
img4 = AutoSizeImage(img4, imgsize, imgsize, True)
|
|
width = img4.Width
|
|
Height = img4.Height
|
|
MS.Close()
|
|
Return img4
|
|
|
|
|
|
|
|
End Function
|
|
|
|
Public Function AutoSizeImage(ByVal oBitmap As Image,
|
|
ByVal maxWidth As Integer,
|
|
ByVal maxHeight As Integer,
|
|
Optional ByVal bStretch As Boolean = False) As Image
|
|
|
|
' Größenverhältnis der max. Dimension
|
|
Dim maxRatio As Single = maxWidth / maxHeight
|
|
|
|
' Bildgröße und aktuelles Größenverhältnis
|
|
Dim imgWidth As Integer = oBitmap.Width
|
|
Dim imgHeight As Integer = oBitmap.Height
|
|
Dim imgRatio As Single = imgWidth / imgHeight
|
|
|
|
' Bild anpassen?
|
|
If (imgWidth > maxWidth Or imgHeight > maxHeight) Or (bStretch) Then
|
|
If imgRatio <= maxRatio Then
|
|
' Größenverhältnis des Bildes ist kleiner als die
|
|
' maximale Größe, in der das Bild angezeigt werden kann.
|
|
' In diesem Fall muss die Bildbreite angepasst werden.
|
|
imgWidth = imgWidth / (imgHeight / maxHeight)
|
|
imgHeight = maxHeight
|
|
Else
|
|
' Größenverhältnis des Bildes ist größer als die
|
|
' maximale Größe, in der das Bild angezeigt werden kann.
|
|
' In diesem Fall muss die Bildhöhe angepasst werden.
|
|
imgHeight = imgHeight / (imgWidth / maxWidth)
|
|
imgWidth = maxWidth
|
|
End If
|
|
|
|
' Bitmap-Objekt in der neuen Größe erstellen
|
|
Dim oImage As New Bitmap(imgWidth, imgHeight)
|
|
|
|
' Bild interpolieren, damit die Qualität erhalten bleibt
|
|
Using g As Graphics = Graphics.FromImage(oImage)
|
|
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
|
|
g.DrawImage(oBitmap, New Drawing.Rectangle(0, 0, imgWidth, imgHeight))
|
|
End Using
|
|
|
|
' neues Bitmap zurückgeben
|
|
Return oImage
|
|
Else
|
|
' unverändertes Originalbild zurückgeben
|
|
Return oBitmap
|
|
End If
|
|
End Function
|
|
|
|
End Class
|