Announcement

Collapse
No announcement yet.

Bitmap zeichnen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bitmap zeichnen

    Ich versuche gerade eine Bitmap auf ein Formular zu zeichnen.
    Leider hat es nicht funktioniert, obwohl es in einem Testprogramm funktioniert hatte.
    Dort war der Code zum Zeichnen allerdings in der Klasse des Formulars drin.
    Ich erstelle im Formular mit CreateGraphics eine neue Graphics.
    Das mache ich so, weil ich es im Module aus irgendwelchen Gründen nicht hinbekommen habe.
    Ich möchte den ganzen Code zum Zeichnen im Module haben und nicht im Formular.
    Deshalb erstellte ich eine Property vom Typ Graphics und übergebe an diese das Ergebnis von CreateGraphics.

    Kann mir jemand Hinweise geben?

    Gibt es eine Möglichkeit ein Gesamt-Bitmap aus vielen kleinen zusammen zu setzen, um es dann als Image an ein PictureBox zuweisen zu können?

  • #2
    Hi!

    Im Modul kannst du folgenden Code Verwenden:
    Code:
    Module Module1
        Friend Function DrawBitmap(ByVal bWidth As Integer, ByVal bHeight As Integer) As System.Drawing.Bitmap
            Dim bmp As New Bitmap(bWidth, bHeight)
            Dim g As Graphics = Graphics.FromImage(bmp)
            g.Clear(Color.Transparent)
            g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
            'Hier kommt dein Code hin
    
            g.Dispose()
            Return bmp
        End Function
    End Module

    Und So wird die Funktion aufgerufen:
    Code:
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.BackgroundImage = DrawBitmap(Me.Width, Me.Height)
        End Sub
    End Class
    Mehrere Bitmaps könntest du in einer Schleife Zeichnen. z.B aus einer Imagelist oder einem Bitmaparray.
    Code:
    Module Module1
        Friend ImageList1 As New ImageList()
    
        Friend Function DrawBitmap(ByVal bWidth As Integer, ByVal bHeight As Integer) As System.Drawing.Bitmap
            Dim bmp As New Bitmap(bWidth, bHeight)
            Dim g As Graphics = Graphics.FromImage(bmp)
            g.Clear(Color.Transparent)
            g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    
            'Hier kommt dein Code hin
    
            'Beispiel für Mehrere Bitmaps
            Dim x As Integer = 0
            Dim y As Integer = 0
            For i As Integer = 0 To ImageList1.Images.Count - 1
                g.DrawImage(ImageList1.Images(i), x, y)
                If x < (bmp.Width - ImageList1.Images(i).Width) Then
                    x += ImageList1.Images(i).Width
                Else
                    x = 0
                    y += ImageList1.Images(i).Height
                End If
            Next i
    
            g.Dispose()
            Return bmp
        End Function
    End Module
    Aufruf:
    Code:
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            PictureBox1.Image = DrawBitmap(Me.Width, Me.Height)
        End Sub
    End Class
    MfG
    Steve
    Zuletzt editiert von Guitarist; 31.03.2011, 08:10.

    Comment

    Working...
    X