Question Need help in saving new adjusted image to File

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
117
Location
UK
Programming Experience
1-3
Hi their :),

I'm writing a small program that saves the Current background image to file once i have drawn on it too, here's what it does :

once i draw on previous image loaded in picturebox, the program then resizes it and save it at my chosen format, Code Bellow.

Code:
        Dim bm As New Bitmap(PicCharSKin.Image)
        Dim MyWidth As Integer = CInt(Val(64)) 'image width. 
        Dim MyHeight As Integer = CInt(Val(32)) 'image height
        Dim thumb As New Bitmap(MyWidth, MyHeight) 'Gets image's new size details
        Dim gfxG As Graphics = Graphics.FromImage(thumb) 'Creates new image
        gfxG.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias 'Smooth image on redrawing
        gfxG.DrawImage(bm, New Rectangle(0, 0, MyWidth, MyHeight), New Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel) 'Redraws the actual image
        savChar.FileName = "char.png" 'Sets filename
        savChar.Filter = "Portable Network Graphics (*.png)|*.png" 'Sets File Type
        savChar.ShowDialog() 'Shows SaveDialog
        thumb.Save(savChar.FileName, System.Drawing.Imaging.ImageFormat.Png) 'Saves Picture and sets format, Could use any almost image format
My problem is the image resizes all fine and save as the format i want, but the new pen i have applied wont save on the image,

Example: Image Loaded Countryside.png, then i Draw on the image ect.. and save, to no avail my pen is not saved on the image.

Maybe i'm missing somthing out here as i've racked my head mulitple times..... and change code over and over againn.......

Cheers for any help in advance.
 

Serge

New member
Joined
May 10, 2012
Messages
2
Programming Experience
5-10
Would you mind posting your drawing code ?
You're saying you draw with a pen, how are you doing it, provide code please.
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
117
Location
UK
Programming Experience
1-3
Here's my Pen code what i use to write with.
Code:
    Private Sub PicCharSKin_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PicCharSKin.MouseMove
        If MouseButtons = Windows.Forms.MouseButtons.Left Then 'Check's to see if left mouse is pressed
            MyGraphics = PicCharSKin.CreateGraphics
            MyPen = New Drawing.Pen(MyColor, MyPenSize.Value)
            Select Case cboShape.Text
                Case "Square"
                    If cboFill.Text = "Filled" Then MyGraphics.FillRectangle(MyPen.Brush, e.X - 4, e.Y - 4, 9, 9) 'next 4 lines use mouse position to start draw rectangle
                    If cboFill.Text = "Hollow" Then MyGraphics.DrawRectangle(MyPen, e.X - 4, e.Y - 4, 7, 7)
                Case "Circle"
                    If cboFill.Text = "Filled" Then MyGraphics.FillEllipse(MyPen.Brush, e.X - 4, e.Y - 4, 9, 9)
                    If cboFill.Text = "Hollow" Then MyGraphics.DrawEllipse(MyPen, e.X - 4, e.Y - 4, 7, 7)
            End Select

            PicCharSKin.Update() 'updates picture box

        End If
    End Sub
i also have this code in the On picurebox click to, hope this helps you.

P.s i missed these

Code:
    Dim MyPen As System.Drawing.Pen
    Dim MyGraphics As Graphics
    Dim MyColor As Color
 

Serge

New member
Joined
May 10, 2012
Messages
2
Programming Experience
5-10
There is your problem.

CreateGraphics() will only draw to the picturebox this one time, once your picturebox needs to repaint, your drawings won't be there anymore.
You have to draw directly to the image & then replace the exisiting image in the picturebox with the new one (drawn).
 

Dunfiddlin

Well-known member
Joined
Jun 15, 2012
Messages
253
Programming Experience
5-10
MyGraphics = PicCharSKin.CreateGraphics......Dim bm As New Bitmap(PicCharSKin.Image)
Well there's your problem. You draw on the picturebox not on the picturebox image but then transfer the image to the new bitmap. There are three possible drawing surfaces in a picturebox. The box, the background image and the image, and you have to be specific about which one you're using.
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
117
Location
UK
Programming Experience
1-3
thank guy for the response's you's gave me, all fixed now, i guess i needed pointing in the right direction :D.
 
Top Bottom