locked
Saving Images RRS feed

  • Question

  • Hello MSDN!

    I recently made a post concerning taking screenshots, while I have not got fully answered what I wanted, I have a small screenshot application made.

    My problem is, when I take a screenshot, it sends the image to a picturebox control, so that the user can decide if they want to save or delete the image.

    If the user clicks Save, it saves the image. BUT the image is 300 to 500kb in size!!! If I open the image in MS Paint, and Re-save it (without editing anything) the image is 20 to 50kb! I am having my program save it as a jpg by using the save method for the picture box:
    PictureBox.save("C:\test.jpg") 

    So I am wondering what am I doing wrong?
    Can someone please help me?

    Thanks!
    Thursday, August 28, 2008 7:45 PM

Answers

  • Highlight Image.Save and press F1 - the Universal Help button. Or, Google Image.Save and press 'I'm feeling lucky'. Or, when you type the first parenthesis after the word Save, there are several options available to you (a total of 5 overloads by my reckoning).

    When you install VB an extensive help system is installed. Likewise, the whole documentation is available through this help system or through the web directly.

    Like I said, the file extension is irrelevant: even though you specify .jpg as your extension, the file is a PNG. For any file, file extension is irrelevant to what the file is. File extensions simply give the operating system a hint as to what to do with the file.

    I don't think anyone is expecting you to find, follow and understand every nuance of VB (in this case) or searching for help on any given command, but it's expected that a rudimentary search will be performed.

    Stephen J Whiteley
    • Proposed as answer by JohnWein Friday, August 29, 2008 5:17 PM
    • Marked as answer by Wovaki Friday, August 29, 2008 5:48 PM
    Friday, August 29, 2008 4:51 PM
    Moderator

All replies

  • What is this PictureBox.save method of which you speak?  Paint saves the image in the format of your choice.  What are you saving?  Try saving the image in the default format (png).  Use Image.Save or Bitmap.Save without specifying an ImageFormat.  JPEG format is not a good choice for screenshots.  With JPEG you'll see blocky artifacts on line art.
    Thursday, August 28, 2008 8:12 PM
  • I use PictureBox.image.save(":C\test.jpg")

    and it specifies a JPEG file right in there, unless I have to do it a different way?
    Thursday, August 28, 2008 8:16 PM
  • One thing about programming, the syntax must be correct.  I guess you mean that you are saving the image in an instance of a picture box using the default ImageFormat.  If so, you should change the extension to ".png".  Everything seems as it should be otherwise.
    Thursday, August 28, 2008 8:34 PM
  • Alright so I tried changing it to .png, but it still saves the files with a big file size, 300kb +/- when I open with Paint and resave its 1/10 of the size.

    I would also like them to be jpeg since it takes less space. Also, all the images I have taken so far have had good quality.



    How my program works is: User presses a button, it takes a screenshot, and loads the shot into a picture box. Then the user can look at the picture through the picture box and decide if they want to save it or not.

    When they save it, it saves whatever image is in the picture box.
    Thursday, August 28, 2008 8:42 PM
  • If you want to save the image in a format other than the default, I suggest you read the documentation.  That's usually a good starting point whenever you use a method.
    Thursday, August 28, 2008 8:51 PM
  • I couldn't find anything on using picturebox.image.save

    and even if I save it in the default format (.png ??) it is still bigger than it should be.
    Thursday, August 28, 2008 8:52 PM
  • firstly: saving the image has nothing to do with a picture box: you need to be aware of the structure of the command you are using.

    The PictureBox has an image property which returns an Image object. The Image object has a save Method. Lookup the Save method in help. You can specify the file type that you save it as (the file extension is irrelevant).

    Regardless, the file size (unless it's a bitmap) is completely dependent on the contents of the image. 300K is not an unreasonable image size for a PNG.



    Stephen J Whiteley
    Thursday, August 28, 2008 9:16 PM
    Moderator
  • If it is completly depended on the image, how come if I open a image with 300k size, and save it with same format, and WITHOUT changing ANYTHING with paint, it is 30k

    Thats a big size difference!
    Thursday, August 28, 2008 9:18 PM
  • You should back track a little:  Start here.
    Thursday, August 28, 2008 9:25 PM
  • Learning how to use search engines is not going to help me out.
    Since I already tried it and found nothing.

    Besides, if people could find EVERYTHING on google, why have these forums here?
    Friday, August 29, 2008 2:40 PM
  • Wovaki said:

    If it is completly depended on the image, how come if I open a image with 300k size, and save it with same format, and WITHOUT changing ANYTHING with paint, it is 30k

    Thats a big size difference!

    What format do you save it as from your program and what format do you save it as from paint? Are you saying that you save the file as a PNG with your program, then from paint you re-save it as a PNG and the file size is different?

    From your code you have posted it looks like you are saving it as a PNG from your program. (that is, you aren't specifying the file type, so it's using the default file type which is PNG - the documentation states this).





    Stephen J Whiteley
    Friday, August 29, 2008 3:23 PM
    Moderator
  • You have shown by your responses in this thread that you cannot find basic information in the documentation.  Lessons in searching and finding information on the internet should be the first thing you attempt to learn to become a proficient programmer.  When something is thoroughly covered in the documentation, your expectation that someone should read the documentation for you and post it to your threads is unreasonable.
    Friday, August 29, 2008 3:27 PM
  • @SJWhiteley

    My program saves the image as a JPEG, when I open that image in Paint, I resave it as a JPEG and the file size is exceptionally different.
    To save the image I use this exactly:
    PictureBox1.Image.Save("C:\test.jpg"

    As far as I know, that is specifying a file type, unless there is a different way, then I would love to hear about this.


    @JohnWein
    I am NOT asking someone to read and post stuff for me!
    I have no clue What the hell this "Documentation" you are talking about it. I'm completely new to programming, just learning and self taught. I'm not looking for someone to do everything for me.

    I don't know what this documentation is, so please tell me what it is, and where I can find it.


    Friday, August 29, 2008 4:35 PM
  • Highlight Image.Save and press F1 - the Universal Help button. Or, Google Image.Save and press 'I'm feeling lucky'. Or, when you type the first parenthesis after the word Save, there are several options available to you (a total of 5 overloads by my reckoning).

    When you install VB an extensive help system is installed. Likewise, the whole documentation is available through this help system or through the web directly.

    Like I said, the file extension is irrelevant: even though you specify .jpg as your extension, the file is a PNG. For any file, file extension is irrelevant to what the file is. File extensions simply give the operating system a hint as to what to do with the file.

    I don't think anyone is expecting you to find, follow and understand every nuance of VB (in this case) or searching for help on any given command, but it's expected that a rudimentary search will be performed.

    Stephen J Whiteley
    • Proposed as answer by JohnWein Friday, August 29, 2008 5:17 PM
    • Marked as answer by Wovaki Friday, August 29, 2008 5:48 PM
    Friday, August 29, 2008 4:51 PM
    Moderator
  • Alright Thank you!

    And I'm sorry for getting angry earlier. And I think I may have found a solution, here is my code:

     
                Dim img As Bitmap = New Bitmap(pb1.Image) 
                ' TextBox1 is the path, TextBox2 is the file name 
                Dim ss As New IO.FileStream(TextBox1.Text + TextBox2.Text + ".jpg", IO.FileMode.Create) 
                img.Save(ss, Imaging.ImageFormat.Jpeg) 
                ss.Flush() 
                ss.Close() 
                ss = Nothing 

    I only did one test, but I used the image.save and saved a file, which produced a big 1mb file!
    I Commented out the image.save and used the above code, and saved the exact same picture, same size and all and it came out with a nice 50k file size.

    I was wondering now if someone wouldn't mind checking over that code and seeing if there is a better way I can do it, or if there is something wrong with the code (that might affect the final image, etc.)

    [EDIT]
    After doing what you said (highlight and press f1) and looking, what it be more efficiant and better to just use image.save as it seems it would be 1 line of code instead of 6?

    Thanks!



    • Edited by Wovaki Friday, August 29, 2008 5:53 PM Thanks
    Friday, August 29, 2008 5:47 PM