Ich habe mir letztens eine Funktion geschrieben mit der man aus einem vorhandenen Image ein TeilImage 'herausschneiden' kann:
Mit Imports
Ohne Imports
Als Klasse
Ich hoffe, dass der Code jemanden helfen konnte.
MfG Mangafreak1995
VB.NET-Quellcode
- Imports System.Drawing
- Public Shared Function LoadImagePart(ByVal img As Image, ByVal rows As Integer, ByVal colums As Integer, ByVal part As Point) As Image
- Dim minw, minh As Integer
- minw = CInt(img.Width / colums)
- minh = CInt(img.Height / rows)
- Dim cur As New Bitmap(minw, minh)
- Using g As Graphics = Graphics.FromImage(cur)
- g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy
- g.DrawImage(img, New Rectangle(0, 0, cur.Width, cur.Height), _
- New Rectangle(minw * part.X, minh * part.Y, cur.Width, cur.Height), GraphicsUnit.Pixel)
- g.Flush()
- End Using
- Return cur
- End Function
VB.NET-Quellcode
- Public Shared Function LoadImagePart(ByVal img As System.Drawing.Image, ByVal rows As Integer, ByVal colums As Integer, ByVal area As System.Drawing.Point) As System.Drawing.Image
- Dim minw, minh As Integer
- minw = CInt(img.Width / colums)
- minh = CInt(img.Height / rows)
- Dim cur As New System.Drawing.Bitmap(minw, minh)
- Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(cur)
- g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy
- g.DrawImage(img, New System.Drawing.Rectangle(0, 0, cur.Width, cur.Height), _
- New System.Drawing.Rectangle(minw * area.X, minh * area.Y, cur.Width, cur.Height), System.Drawing.GraphicsUnit.Pixel)
- g.Flush()
- End Using
- Return cur
- End Function
VB.NET-Quellcode
- Public Class ImageSeperator
- Private baseImage As System.Drawing.Image
- Public ReadOnly Property Image As System.Drawing.Image
- Get
- Return baseImage
- End Get
- End Property
- Private tblSize As System.Drawing.Size
- Public Property TableSize As System.Drawing.Size
- Get
- Return tblSize
- End Get
- Set (ByVal value As System.Drawing.Size)
- If value.Height > 0 And value.Width > 0 Then
- tblSize = value
- RaiseEvent TableSizeChanged(Me)
- Else
- Throw New System.ArgumentOutOfRangeException("Values must be greater than 0.")
- End If
- End Set
- End Property
- Public Event TableSizeChanged(ByVal sender As Object)
- Private cuttedImages As System.Drawing.Image()
- Public Function Cell(ByVal cellPoint As System.Drawing.Point) As Image
- Return Cell(cellPoint.X, cellPoint.Y)
- End Function
- Public Function Cell(ByVal x As Integer, ByVal y As Integer) As Image
- If x < 0 Or y < 0 Then _
- Throw New System.ArgumentOutOfRangeException("Value must be greater than or equal 0.")
- Dim i As Integer = x * tblSize.Width + y
- If i >= cuttedImages.Length() Then _
- Throw New System.ArgumentOutOfRangeException("Values must be greater than 0.")
- Return cuttedImages.Item(i)
- End Function
- Private Sub ReCutImage(ByVal sender As Object) Handles Me.TableSizeChanged
- Dim minw, minh As Integer
- minw = CInt(baseImage.Width / tblSize.X)
- minh = CInt(baseImage.Height / tblSize.Y)
- Dim cur As System.Drawing.Bitmap
- Dim images As New System.Collections.Generic.List(Of System.Drawing.Image)
- For x As Integer = 0 To tblSize.Width - 1
- For y As Integer = 0 To tblSize.Height - 1
- cur = New System.Drawing.Bitmap(minw, minh)
- Using g As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(cur)
- g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy
- g.DrawImage(img, New System.Drawing.Rectangle(0, 0, minw, minh), _
- New System.Drawing.Rectangle(minw * x, minh * y, minw, minh), System.Drawing.GraphicsUnit.Pixel)
- g.Flush()
- End Using
- images.Add(cur)
- Next
- Next
- cuttedImages = images.ToArray()
- End Sub
- Public Sub New(ByVal img As System.Drawing.Image)
- baseImg = img
- TableSize = New Point(1, 1)
- End Sub
- End Class
Ich hoffe, dass der Code jemanden helfen konnte.
MfG Mangafreak1995
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Mangafreak1995“ () aus folgendem Grund: Klasse hinzugefügt (auf Wunsch von Unwesen), Download entfernt