Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27368

Drawing to a bitmap

$
0
0
Hi,

in VB2010, I decided to make my own chart control, and I was looking for a method to draw tens of Thousand pixels at a fair speed.

I found out that the best way to do this is to draw all the data points onto a memory bitmap, and when all pixels are drawn, copy the bitmap to the form.

See example code : this draws 200x200 = 40.000 datapoints at high speed.

The problem is that the SetPixel method seems to be the only method to draw something on the bitmap (before is't copied to the form).

I would like to know how I can draw lines, rectangles etc... to the bitmap (once again : BEFORE it's drawn on the form)

Code:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim b As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
        For y = 1 To 200
            For x = 1 To 200
                b.SetPixel(x, y, Color.Yellow)
            Next
        Next
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim b As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
        For y = 1 To 200
            For x = 1 To 200
                b.SetPixel(x, y, Color.FromArgb(CInt(Rnd() * 255), CInt(Rnd() * 255), CInt(Rnd() * 255)))
            Next
        Next
        e.Graphics.DrawImage(b, 0, 0)
    End Sub

    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Refresh()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27368

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>