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

Can lockbits make this graphics operation faster?

$
0
0
Here is a complete program. It initially sets a bitmap to red, then when you click on the "Update" button, it turns it blue. It displays the images in PictureBox1 and PictureBox2.

The method I use, is .SetPixel - There is a reason for this as I have let's say 10,000 images that I will eventually process one after the other. I will need to use this method.

I searched google and found that there is some lock/unlock bits method that can be used on an image and that supposedly it speeds things up. If you know about locking bits, can you look at this and evaluate if it can speed up the .SetPixel operation in this example? If yes, can you give an example on how I would implement it.

Code:

Public Class Form1


    Dim bmp1 As New Bitmap(200, 200)
    Dim bmp2 As New Bitmap(200, 200)


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        For y As Integer = 0 To 199
            For x As Integer = 0 To 199
                bmp1.SetPixel(x, y, Color.Red)
            Next
        Next


        PictureBox1.Image = bmp1
    End Sub


    Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
        bmp2 = CType(bmp1.Clone, Bitmap)


        For y As Integer = 0 To 199
            For x As Integer = 0 To 199
                bmp2.SetPixel(x, y, Color.Blue)
            Next
        Next


        PictureBox2.Image = bmp2
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27349

Trending Articles



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