excuseme :)
sorry I have some problem here, I make a simple paint using vb 6.0
I already can save the image that I load, but something like brush and pencil that I draw in the image can't include :(
after I save and open it, it just the image have been save. The brush and pencil is not there..
can anyone help me please ?
thanks before

Dani AI

Generated

You are close. What is tripping you up is that VB6 keeps two surfaces in a PictureBox: the loaded bitmap (Picture) and the persistent back buffer (Image). is right about drawing onto the back buffer, but there is one extra step many people miss: after you load the base image, you must copy it into the back buffer before you start brushing, otherwise your strokes will not be part of what gets saved.

Here is a minimal pattern that tends to work reliably and keeps mouse drawing smooth:

' one-time init (e.g., Form_Load)
With Picture1
    .AutoRedraw = True
    .ScaleMode = vbPixels
    .BackColor = vbWhite
End With

' after you choose a file
Set Picture1.Picture = LoadPicture("C:\path\photo.bmp")
Picture1.Cls                                  ' clear the back buffer
Picture1.PaintPicture Picture1.Picture, 0, 0  ' push Picture into Image

' simple "brush" using line segments
Private mDown As Boolean, lx As Single, ly As Single

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mDown = True: lx = X: ly = Y
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If mDown Then
        Picture1.DrawWidth = 4                  ' brush size
        Picture1.Line (lx, ly)-(X, Y), Picture1.ForeColor
        lx = X: ly = Y
    End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mDown = False
End Sub

Now your strokes live in the back buffer along with the photo, so when you save, target that back buffer (not Picture). Extra tips: if the photo is larger than the control, either enable AutoSize or scale with PaintPicture src, 0, 0, destW, destH. VB6’s native save produces BMP/WMF; for PNG/JPEG use GDI+ or WIA, or a drawing control as suggested.

Recommended Answers

All 3 Replies

FYI, I already try with any code that I find in internet.
i feel so stressed by this project. I find the code by video, article, blog etc.
I try all my best.
Until last week I join this site and post a thread.
And another FYI I already try to search an example like that link you give before post my first thread, and I still confused because they use many module :(
I only find a simple way to save. Only for save, but I think it really complicated.
but anyway, thanks a lot for your advice :)

I saw your note on needing to save a picturebox you are drawing to.

There are two things you need to do

  1. Set AutoRedraw = True ( before you start drawing )
  2. Save the Image property of the Picturebox not the Picture property

Example:

                 Picture1.AutoRedraw = True
                 Picture1.Line  ( 0,0) - ( 300,300)
                 SavePicture  Picture1.Image, "C:\temp\junk.bmp"

Note that another option is to replace the standard picturebox with an off-the-shelf commercial drawing component designed for this purpose. This can make it very easy to quickly create a very useful drawing program, or to add drawing features to a larger application.

I hope this is helpful.

  • Jeff

    • Please include a copy of this message with any reply on this topic
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.