Results 1 to 30 of 30

Thread: [RESOLVED][2008]Save Resources?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    [RESOLVED][2008]Save Resources?

    I was wondering if there was a way to save an image(a resource of the program)? My program now what it does is you select the image you want to see but right now there is no way to save it. How can i do it if being able to save resources is not an option?

    This is how i load the resoruce.bitmap:

    Case "Widescreen"
    picturebox1.Image = My.Resources.noImageAvailable

    Based on that i want the user to be able to save the image that is placed into the picture box!
    Last edited by pirate16; May 17th, 2008 at 11:59 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Save Resources?

    i don't think thats possible. my.resources resources are added at design time but can't be added at runtime. you could save the image to your my.application.info.directorypath (where the executable is) then save the filename in my.settings

    EDIT: or just save the filename + path in my.settings

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: Save Resources?

    How would i set that up so it saves where the executable is? I'm still new at vb and learning so some things i am still confuzed about . Also i am not adding to the resources im taking away from the resources and adding them to wherever the user wishes to save lol but if you say its not possible then its not possible .

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Save Resources?

    to add a my.settings setting

    menus - Project-->Properties-->Settings

    change Name to "test", Type to string, + scope to user.

    to try it add this to your form, then run the project + doubleclick the form:

    vb Code:
    1. Private Sub form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick
    2.      My.Settings.test = "test"
    3.      My.Settings.Save()
    4.      MsgBox(My.Settings.test)
    5. End Sub

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: Save Resources?

    Alright now how will this alloq me to save the image where the .exe is at? What do i have to do to make it so it can save?

    Thanks for your help btw
    Last edited by pirate16; May 11th, 2008 at 06:13 PM.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Save Resources?

    to save an image anywhere you need to create a new bitmap, then save it.

    vb Code:
    1. dim img as new bitmap(filename here)
    2. img.save(new filename here, System.Drawing.Imaging.ImageFormat.Bmp)

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: Save Resources?

    So if i add all that coding its as simple as saying image1.image.save(location) and it will work or is it more complicated? Is there a way you can set this up for me? I can send you my project folder so you can try it out :d.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Save Resources?

    have a try at it yourself. you'll learn more

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: Save Resources?

    Alright i did it myself but it wont work. I click the button to save the image and it does nothing, what do i have to place in the file name here part of the code? Sorry this is probably really annoying right now.
    Last edited by pirate16; May 11th, 2008 at 06:33 PM.

  10. #10

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    The code he game me to use to save it here:

    1.
    dim img as new bitmap(filename here)
    2.
    img.save(new filename here, System.Drawing.Imaging.ImageFormat.Bmp)

  12. #12
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008]Save Resources?

    If you want to just save image of picture box then following one line code is enough. You can choose different formats to save form ImageFormat.

    Code:
    PictureBox1.Image.Save("c:\test.bmp", Imaging.ImageFormat.Bmp)

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    What if i want the user to choose where to save if i have a save dialog?

  14. #14
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008]Save Resources?

    Have you read up on the SaveFileDialog on MSDN?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    Yes i know how to use it but how would i place that code into it to make sure it does the right thing without error?

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008]Save Resources?

    read up on the SaveFileDialog on MSDN
    it shows you how to avoid errors

  17. #17
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008]Save Resources?

    vb Code:
    1. Private Sub button1_Click(sender As Object, e As System.EventArgs)
    2.     Dim saveFileDialog1 As New SaveFileDialog()
    3.  
    4.     saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|All files (*.*)|*.*"
    5.     saveFileDialog1.FilterIndex = 2
    6.     saveFileDialog1.RestoreDirectory = True
    7.  
    8.     If saveFileDialog1.ShowDialog() = DialogResult.OK Then
    9.         img.save(saveFileDialog1.filename, Imaging.ImageFormat.Bmp)
    10.     End If
    11. End Sub

  18. #18

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    I keep getting Dim img As New Bitmap(filename here) error with here underlined blue Comma or expression needed and img underlined blue with error "declaration expected"
    Last edited by pirate16; May 14th, 2008 at 01:55 PM.

  19. #19

  20. #20

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    dim img as new bitmap(filename here)
    img.save(new filename here, System.Drawing.Imaging.ImageFormat.Bmp)

    This is the code where i get the error.

  21. #21
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2008]Save Resources?

    Is that your exact code? What is the exact error messages?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  22. #22
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008]Save Resources?

    Quote Originally Posted by pirate16
    dim img as new bitmap(filename here)
    img.save(new filename here, System.Drawing.Imaging.ImageFormat.Bmp)

    This is the code where i get the error.
    Have u seen the code posted .paul.? Use that code.

  23. #23

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    I did use that code lol thats the code giving me the error. The error is:

    (filename here) here is underlined blue and it says comma, ')', or a valid expression continuation expected.

    and img.save(new filename here) file name here underlined with same error and img udnerlined with error: name img is not declared although i did put dim img!

  24. #24
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008]Save Resources?

    post your COMPLETE code + someone might help you.
    looking at your previous posts in this thread it looks like you've got confused.

  25. #25

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    Code:
    Public Class Form1
        Dim img As New Bitmap(filename here) 
        Private documentTitle As String
        Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
            Select Case ListBox1.SelectedItem.ToString()
                Case "Save"
                    PictureBox1.Image = My.Resources.Save_Button
            End Select
        End Sub
    
    
    
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    
    
            Dim saveFileDialog1 As New SaveFileDialog()
    
    
    
            saveFileDialog1.Filter = "bmp files (*.bmp)|*.bmp|All files (*.*)|*.*"
    
            saveFileDialog1.FilterIndex = 2
    
            saveFileDialog1.RestoreDirectory = True
    
    
    
            If saveFileDialog1.ShowDialog() = DialogResult.OK Then
    
                img.save(saveFileDialog1.FileName, Imaging.ImageFormat.Bmp)
                documentTitle = saveFileDialog1.FileName
            End If
    
    
        End Sub
    
    
    
    End Class
    Dim img As New Bitmap(filename here) - THIS IS WHERE I GET ERROR on the here part. The image one is no longer there but yeah.

  26. #26
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008]Save Resources?

    vb Code:
    1. Dim img As New Bitmap(filename here)

    you're supposed to substitute - filename here - for the filename of the image file.

  27. #27

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    I figured that much lmao. *smack self in head* so basically every time the user changes the image in the list box i dim it as the new image name? Also when i hit the save button it only saves the one image i set up in the dim image as new bitmap(my.resources.save_button). IS there a way to save save as whats in the image box? Cause when i say dim image as new bitmap(picturebox1.image) it comes up with some handling error.
    Last edited by pirate16; May 16th, 2008 at 08:08 PM.

  28. #28
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2008]Save Resources?

    Quote Originally Posted by Deepak Sakpal
    If you want to just save image of picture box then following one line code is enough. You can choose different formats to save form ImageFormat.

    Code:
    PictureBox1.Image.Save("c:\test.bmp", Imaging.ImageFormat.Bmp)
    Deepak Sakpal told you how to do that 4 days ago!

  29. #29

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    50

    Re: [2008]Save Resources?

    I know but how do i set that up so the user can select where to save? Nevermind i figured it out . Thanks for this guys i know it was annoying but you dont know how much this helped!!
    Last edited by pirate16; May 16th, 2008 at 09:37 PM.

  30. #30
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008]Save Resources?

    Quote Originally Posted by pirate16
    I know but how do i set that up so the user can select where to save? Nevermind i figured it out . Thanks for this guys i know it was annoying but you dont know how much this helped!!
    ok then you can now mark the thread as resolved and don't forget to rate our post

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