[RESOLVED] Best method for drawing to picturebox
I use VB6.
I am drawing to a 1000x1000 picturebox with different colours based on areas of a map. I am trying to work out the fastest way to draw this pixel by pixel.
At the moment I am using setpixel, which is okay if I am not zoomed in but when I zoom in it not only takes serious amounts of time, but also memory and it crashes with the "can't create AutoRedraw image" error (meaning the buffer's too large)..BTW zooming in multiplies the picturebox size because of what I am doing, so 3x zoom is a 3000x3000 picturebox.
I have tried using BitBlt but I can't seem to work out how to draw specific colours to each pixel with it if at all possible. I've realised I *could* have a legend and have BitBlt grab the image from there to paste onto my map, and I might have to do that if I can't find a better solution.
I have uploaded a sample of a zoomed in (4x zoom so each box is 3x3 with a black border) at http://i10.photobucket.com/albums/a117/SmUX/sample.gif
Has anyone got any thoughts or suggestions for the best way to achieve this? Hopefully with some code or link to where to learn about it :-)
Is there any way to draw squares of a specific colour to a specific point of a picturebox, perhaps?
Re: Best method for drawing to picturebox
Is there any way to draw squares of a specific colour to a specific point of a picturebox, perhaps?
Picture1.ForeColor = vbRed
Picture1.Line (10, 10)-(50, 50), , BF
I use ScaleMode = Pixel for both the Form and the PictureBox
Re: Best method for drawing to picturebox
Just for the fun of it place a large PictureBox on a large Form and then click on the Form
Code:
Private Sub Form_Click()
Dim CX, CY, F, F1, F2, I
Picture1.BorderStyle = 1 ' Set BorderStyle to Fixed Single
Picture1.ScaleMode = 3 ' Set ScaleMode to Pixels.
CX = Picture1.ScaleWidth / 2 ' Get horizontal center.
CY = Picture1.ScaleHeight / 2 ' Get vertical center.
Picture1.DrawWidth = 8 ' Set DrawWidth.
For I = 50 To 0 Step -2
F = I / 50 ' Perform interim
F1 = 1 - F: F2 = 1 + F ' calculations.
Picture1.ForeColor = QBColor(I Mod 15) ' Set foreground color.
Picture1.Line (CX * F1, CY * F1)-(CX * F2, CY * F2), , BF
Next I
DoEvents
If CY > CX Then ' Set DrawWidth.
Picture1.DrawWidth = Picture1.ScaleWidth / 25
Else
Picture1.DrawWidth = Picture1.ScaleHeight / 25
End If
For I = 0 To 50 Step 2 ' Set up loop.
F = I / 50 ' Perform interim
F1 = 1 - F: F2 = 1 + F
Picture1.Line (CX * F1, CY)-(CX, CY * F1) ' Draw upper-left.
Picture1.Line -(CX * F2, CY) ' Draw upper-right.
Picture1.Line -(CX, CY * F2) ' Draw lower-right.
Picture1.Line -(CX * F1, CY) ' Draw lower-left.
Picture1.ForeColor = QBColor(I Mod 15) ' Change color each time.
Next I
DoEvents
End Sub