Results 1 to 14 of 14

Thread: Save draw to file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Save draw to file

    I have used gdi to draw image on picturebox, now i want save the image on file. How to make it?

  2. #2
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: Save draw to file

    Picturebox1.Image.Save(filename)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    Picturebox1.Image.Save(filename)

    Error!!!

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Save draw to file

    Error!!! isn't too helpful in helping you. What is the error?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    If i copy the picturebox.image to another the picturebox2.image is null!
    Why?

  6. #6
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Save draw to file

    What is the code you are using to perform the drawing? my guess is that you are using the CreateGraphics method, and yes, that will put GDI+ pictures on the picturebox, but it will forget about them right away. For example, if after you draw the images, you minimize and then restore the form, is the picture still there? if it's not, then that means saving that image isn't going to do much for you, you would have to do your drawing onto a bitmap object, instead of just on the screen.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    With openfile
    Dim myGraphics As Graphics
    .CheckFileExists = True
    .ShowReadOnly = False
    .Filter = "Tutti i file immagine(*.png)|*.png;"
    .FilterIndex = 2
    If .ShowDialog = DialogResult.OK Then

    Dim g As Graphics = Toolbar.CreateGraphics
    Dim smallImage As Image = Image.FromFile(.FileName)
    g.DrawImage(smallImage, 0, 0)
    g.Dispose()
    End If
    End With

    This code is used for 14 image.

  8. #8
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Save draw to file

    So you are trying to load icon pictures to a toolbar? Why can't you just use the image property of the ToolbarItems

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    toolbar is the name of the picturebox

  10. #10
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Save draw to file

    Hmm, I still don't get why you're using GDI+ for this, when the picturebox has the image property.. But, I'll assume you have a reason. here's one method.

    VB Code:
    1. Dim gr As Graphics 'Make a new graphics object
    2.         Dim Bm As New Bitmap(PictureBox1.Width, PictureBox1.Height) 'Create a memory bitmap object the size of your picturebox
    3.         gr = Graphics.FromImage(Bm) 'Assing the graphics object to the memory bitmap
    4.         gr.DrawImage(Image.FromFile("z:\mybcd.gif"), 0, 0) 'Draw the image to the memory bitmap object.
    5.         PictureBox1.Image = Bm 'Set the picture to the memory bitmap
    6.         PictureBox1.Image.Save("Z:\mybcd.bmp", Imaging.ImageFormat.Bmp) 'Save it as a bitmap file (lots more formats in Imaging.ImageFormat)
    7.         gr.Dispose() 'Always dispose graphics objects.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    Ok but i don't have the image, i'm drawing the image on the picturebox. and later i want save this file image.




    I made this.


    and now i want save this file ok.

  12. #12
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Save draw to file

    This is a duplicate thread of the one that lots of people answered this question in.

    http://www.vbforums.com/showthread.php?t=385477

    However, I'll make one final stab at it, modifying my code above.

    VB Code:
    1. Dim gr As Graphics 'Make a new graphics object
    2.         Dim Bm As Image = Image.FromFile("firstimage.png")
    3.         Dim Bm2 As Image = Image.FromFile("secondimage.png")
    4.         Dim mergedbitmap As New Bitmap(Bm.Width + Bm2.Width, Bm.Height) 'Create a memory bitmap object the size of your two images
    5.         gr = Graphics.FromImage(mergedbitmap) 'Assing the graphics object to the memory bitmap
    6.         gr.DrawImage(Bm, 0, 0) 'Draw the first image to the memory bitmap object.
    7.         gr.DrawImage(Bm2, Bm.Width, 0) 'Draw the second image to the memory bitmap object.
    8.         PictureBox1.Image = mergedbitmap 'Set the picture to the memory bitmap
    9.         PictureBox1.Image.Save("Z:\merged.ping", Imaging.ImageFormat.Png) 'Save it as a png file
    10.         gr.Dispose() 'Always dispose graphics objects.

    In the future, it's considered rude to start a thread about something when lots of people have given you advice already about it.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    ok but if I want to load the images with openfile dialog as I make to join the images? I then put single every memory path and them markup to the end.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    25

    Re: Save draw to file

    Ok i'm used a listbox to save the path of file and later i recall the file to draw te image and save the new bitmap.

    Dim Bm As Image = Image.FromFile(list.Items(0).ToString)
    Dim Bm2 As Image = Image.FromFile(list.Items(1).ToString)
    Dim Bm3 As Image = Image.FromFile(list.Items(2).ToString)
    Dim Bm4 As Image = Image.FromFile(list.Items(3).ToString)
    Dim Bm5 As Image = Image.FromFile(list.Items(4).ToString)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width