PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Saving a picture without manually choosing the location?-VBForums
Results 1 to 10 of 10

Thread: Saving a picture without manually choosing the location?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Question Saving a picture without manually choosing the location?

    I'm making a screen capturing program, and I am trying to save the image. I can do it as a 'save as' like this

    save as Code:
    1. savefiledialog1.Title = "Save File"
    2.             savefiledialog1.FileName = "Capture"
    3.             savefiledialog1.Filter = "JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|PNG (*.png)|*.png"
    4.             If savefiledialog1.ShowDialog() = DialogResult.OK Then
    5.                 PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
    6.             End If

    How could I do a quick save option so that it auto saves to a certain location that the user doesn't have to choose and as a .jpg?
    Sorry if it's really simple, I've only recently started learning it at college

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,297

    Re: Saving a picture without manually choosing the location?

    You are using a save file dialog so obviously it will ask you where to save the file. That's the point of it.

    Code:
    PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
    savefiledialog1.FileName is the path and file name. Hard code that.

    Side note look at your last entry. "System.Drawing.Imaging.ImageFormat.Bmp"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Re: Saving a picture without manually choosing the location?

    I can do the file name, I am unsure how to add the location in?

    I have
    Quick save Code:
    1. quicksave.FileName = "screenshot" & intCount + 1
    2.  
    3.         PictureBox1.Image.Save(quicksave.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)

    and I want it to save to "C:\Users\Karl\Desktop\Screenshot"?

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,297

    Re: Saving a picture without manually choosing the location?

    What is this quicksave.filename and intCount +1 all about? As i previously said you need to hard code the location. When i say hard code write the string value exactly as how you would see it.

    For example if you wanted to save the picture from multiple instances in your application with possibly a different location each time you can make a new method as such.

    vb Code:
    1. Private Sub SavePictureBox(ByVal path As String)
    2.         PictureBox1.Image.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg)
    3. End Sub

    Now when calling this method you would pass an argument.

    vb Code:
    1. SavePictureBox("C:\Users\Karl\Desktop\Screenshot\filename.jpeg")


    vb Code:
    1. PictureBox1.Image.Save("C:\Users\Karl\Desktop\Screenshot\filename.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Re: Saving a picture without manually choosing the location?

    Ahh thank you, I misunderstood the first time, it is working now.

    The intCount is the number of files in that folder, so by adding 1 to it, it should be a unique filename.
    I did it like this to include the intCount
    vb Code:
    1. PictureBox1.Image.Save("C:\Users\Karl\Desktop\Screenshot\" & quicksave.FileName & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

  6. #6
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,297

    Re: Saving a picture without manually choosing the location?

    If you want an unique count why not time stamp it? But still what is this quicksave.filename? Can you please post your full code.

    Code:
            PictureBox1.Image.Save(String.Format("C:\Users\Karl\Desktop\Screenshot\{0}{1}.jpg", quicksave.FileName, intCount + 1), System.Drawing.Imaging.ImageFormat.Jpeg)

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Re: Saving a picture without manually choosing the location?

    I can't remember why it was originally called "quicksave.filename" it is now strFilename

    all code Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapture.Click
    4.         Me.Opacity = 0
    5.         Timer1.Enabled = True
    6.         btnSave.Enabled = True
    7.         btnQuickSave.Enabled = True
    8.     End Sub
    9.  
    10.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    11.         Dim bounds As Rectangle
    12.         Dim screenshot As System.Drawing.Bitmap
    13.         Dim graph As Graphics
    14.         bounds = Screen.PrimaryScreen.Bounds
    15.         screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
    16.         graph = Graphics.FromImage(screenshot)
    17.         graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
    18.         PictureBox1.Image = screenshot
    19.         Timer1.Enabled = False
    20.         Me.Opacity = 100
    21.     End Sub
    22.  
    23.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    24.         'If the directory doesn't exist, create it
    25.         If Not My.Computer.FileSystem.DirectoryExists("C:\Users\Karl\Desktop\Screenshot") Then
    26.             My.Computer.FileSystem.CreateDirectory("C:\Users\Karl\Desktop\Screenshot")
    27.         End If
    28.         'Count how many files are in the directory
    29.         Dim counter = My.Computer.FileSystem.GetFiles("C:\Users\Karl\Desktop\Screenshot")
    30.         Dim intCount As Integer
    31.         intCount = CStr(counter.Count)
    32.  
    33.         'Save dialog
    34.         Dim savefiledialog1 As New SaveFileDialog
    35.             savefiledialog1.Title = "Save File"
    36.             savefiledialog1.FileName = "Capture" & intCount + 1
    37.             savefiledialog1.Filter = "JPEG (*.jpg;*.jpeg;*.jpe;*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|PNG (*.png)|*.png"
    38.             If savefiledialog1.ShowDialog() = DialogResult.OK Then
    39.                 PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
    40.             End If
    41.     End Sub
    42.  
    43.     Private Sub btnQuickSave_Click(sender As System.Object, e As System.EventArgs) Handles btnQuickSave.Click
    44.         Dim strfilename As String
    45.         If Not My.Computer.FileSystem.DirectoryExists("C:\Users\Karl\Desktop\Screenshot") Then
    46.             My.Computer.FileSystem.CreateDirectory("C:\Users\Karl\Desktop\Screenshot")
    47.         End If
    48.  
    49.         'Count how many files are in the directory
    50.         Dim counter = My.Computer.FileSystem.GetFiles("C:\Users\Karl\Desktop\Screenshot")
    51.         Dim intCount As Integer
    52.         intCount = CStr(counter.Count)
    53.  
    54.         strFilename = "screenshot" & intCount + 1
    55.         PictureBox1.Image.Save("C:\Users\Karl\Desktop\Screenshot\" & strFilename & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
    56.     End Sub
    57. End Class

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,839

    Re: Saving a picture without manually choosing the location?

    btw - there is a set of methods available that will combine paths and filenames - part of the System.IO namespace

    they work like this:

    Code:
    Dim strReportFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("reportfolder")
    Dim strStagingFolder As String = Path.Combine(strReportFolder, "staging")
    Dim strBusyFile As String = Path.Combine(strStagingFolder, "Busy.txt")
    That first Dim gets the path from a web.config file - you could just as easily hardwire that but if you are going to run this app elsewhere you need a way to make that more "variable"

    Code:
      <appSettings>
        <add key="reportfolder" value="D:\ACS Desktop\AWC\reporting"/>
    Attached Images Attached Images  

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2011
    Posts
    67

    Re: Saving a picture without manually choosing the location?

    Quote Originally Posted by szlamany View Post
    btw - there is a set of methods available that will combine paths and filenames - part of the System.IO namespace

    they work like this:

    Code:
    Dim strReportFolder As String = System.Web.Configuration.WebConfigurationManager.AppSettings("reportfolder")
    Dim strStagingFolder As String = Path.Combine(strReportFolder, "staging")
    Dim strBusyFile As String = Path.Combine(strStagingFolder, "Busy.txt")
    That first Dim gets the path from a web.config file - you could just as easily hardwire that but if you are going to run this app elsewhere you need a way to make that more "variable"

    Code:
      <appSettings>
        <add key="reportfolder" value="D:\ACS Desktop\AWC\reporting"/>
    When you say to use the variable if I want to use it elsewhere, I have now changed it to use environment.username instead of "karl". I am not sure if that is the same thing but programmed differently or if you are talking about different?

  10. #10
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,839

    Re: Saving a picture without manually choosing the location?

    You are hardwiring Desktop\Screenshot though - if it's a personnal use app - or you can force people to create a folder on their desktop (some would say a desktop should only have SHORTCUTS - never a folder) then you have no issues.

    Otherwise you should put the path in your app.config files - winforms have one of those - right?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width