How would I create a bitmap from scratch in VB? So I could make something like msPaint.
Printable View
How would I create a bitmap from scratch in VB? So I could make something like msPaint.
This is actually pretty easy, depending on how advanced you want to make the drawing tools.
Try This:
- Open a new project in VB
- Add a PictureBox control (Picture1)
- Add a CommandButton (Command1)
- Copy the code below to the form
If you hold down the left mouse button, you can draw on the picture box, and if you press the button, the picture will get saved to C:\MyPicture.bmp.Code:
Private Sub Form_Load()
Picture1.AutoRedraw = True
Command1.Caption = "SAVE"
End Sub
Private Sub Command1_Click()
SavePicture Picture1.Image, "C:\MyPicture.bmp"
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static LastX As Single
Static LastY As Single
If Button = vbLeftButton Then
Picture1.Line (LastX, LastY)-(X, Y), vbRed
End If
LastX = X
LastY = Y
End Sub
You can use the Picture1.PSet method to draw a dot at a give x,y location.
You can use the Picture1.Line method to draw lines, open boxes, and filled boxes.
You can use the Picture1.Circle methode to draw open circles, filled circles, open elipses and filled elipses.
Have fun !!!
Thank you. I 've been looking everywhere for that. It's exactly what I needed. You rock!