|
-
Jan 24th, 2008, 11:55 AM
#1
Thread Starter
PowerPoster
[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?
Last edited by smUX; Jan 24th, 2008 at 11:58 AM.
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Jan 24th, 2008, 08:54 PM
#2
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
-
Jan 24th, 2008, 09:10 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|