saveFileDialog

How to skip it?

Page 1 of 1

11 Replies - 2680 Views - Last Post: 27 May 2010 - 11:41 PM Rate Topic: -----

#1 Garnaal   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 04-September 09

saveFileDialog

Posted 26 May 2010 - 03:41 PM

Hello,

well I'm going to get straight to the point.
I've created a tool that can take a screen shot, and it saves it of course.
BUT, there is user input involved in the saving, and i want to remove that.
you select the directory to save even before you begin to take the screen shot.
so the savefiledialog.showdialog() isn't actually necessary.

So can anyone tell me how to basically skip the dialog?


Garnaal.

Is This A Good Question/Topic? 0
  • +

Replies To: saveFileDialog

#2 elbielefeld   User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 217
  • Joined: 18-May 10

Re: saveFileDialog

Posted 26 May 2010 - 04:11 PM

Hi Garnaal,

you don't want user input? Then delete the line savefiledialog.showdialog() :>
Was This Post Helpful? 0
  • +
  • -

#3 Searock   User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 259
  • Joined: 15-September 09

Re: saveFileDialog

Posted 26 May 2010 - 05:15 PM

Can you post your code so that we can correct you?
Was This Post Helpful? 0
  • +
  • -

#4 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: saveFileDialog

Posted 26 May 2010 - 06:14 PM

Use this:

System.IO.File.WriteAllBytes(filePath, bytes);



Give it the filepath where to save it, you'd have to set that one without user input as a string.

And give it the bytes to save, probably converting the image to a byte[] array.
Was This Post Helpful? 0
  • +
  • -

#5 Garnaal   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 04-September 09

Re: saveFileDialog

Posted 26 May 2010 - 11:53 PM

@elbielefeld
If I do that, it wont save anything!


@Searock
this is the part for the actual saving.
            if (saveScreenshot.ShowDialog() == DialogResult.OK)
            {
                this.Hide();
                bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                bmpScreenshot.Save(saveScreenshot.FileName, ImageFormat.Png);
                this.Show();
            }




@stapia.gutierrez
And how do I convert it to a byte array?
Was This Post Helpful? 0
  • +
  • -

#6 Charles:)   User is offline

  • D.I.C Regular

Reputation: 149
  • View blog
  • Posts: 359
  • Joined: 26-November 09

Re: saveFileDialog

Posted 27 May 2010 - 04:19 AM

Just get rid of the 'if' statement so that you have:

this.Hide();
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bmpScreenshot.Save(saveScreenshot.FileName, ImageFormat.Png);
this.Show();


This post has been edited by Charles:): 27 May 2010 - 04:20 AM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6258
  • View blog
  • Posts: 24,026
  • Joined: 23-August 08

Re: saveFileDialog

Posted 27 May 2010 - 04:39 AM

Well, except that you need to provide the file name instead of saveScreenshot.FileName in the Save command.
Was This Post Helpful? 0
  • +
  • -

#8 Garnaal   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 04-September 09

Re: saveFileDialog

Posted 27 May 2010 - 02:15 PM

That does not work people, I've tried that before I started this topic here!
Any other solutions?
Was This Post Helpful? 0
  • +
  • -

#9 JITHU   User is offline

  • D.I.C Head
  • member icon

Reputation: 62
  • View blog
  • Posts: 201
  • Joined: 02-July 07

Re: saveFileDialog

Posted 27 May 2010 - 02:38 PM

View PostGarnaal, on 27 May 2010 - 09:15 PM, said:

That does not work people, I've tried that before I started this topic here!
Any other solutions?


Did you try what JackOfAllTrades said, that's replacing saveScreenshot.FileName with the path where you want to save the image.

Something like this:
bmpScreenshot.Save("C:\\MyScreenshot.png", ImageFormat.Png);


or you can use the FolderBrowserDialog to ask the user to select the folder where he wants to save all of the screenshots.
You can use the "SelectedPath" property of FolderBrowserDialog to get the folder selected by the user.
After that, you've to just concatenate together the folder and the filename and pass it to the Save method.

bmpScreenshot.Save(folder + "\\MyScreenshot.png", ImageFormat.Png);

Was This Post Helpful? 0
  • +
  • -

#10 Garnaal   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 04-September 09

Re: saveFileDialog

Posted 27 May 2010 - 03:12 PM

View PostJITHU, on 27 May 2010 - 10:38 PM, said:

View PostGarnaal, on 27 May 2010 - 09:15 PM, said:

That does not work people, I've tried that before I started this topic here!
Any other solutions?


Did you try what JackOfAllTrades said, that's replacing saveScreenshot.FileName with the path where you want to save the image.

Something like this:
bmpScreenshot.Save("C:\\MyScreenshot.png", ImageFormat.Png);


or you can use the FolderBrowserDialog to ask the user to select the folder where he wants to save all of the screenshots.
You can use the "SelectedPath" property of FolderBrowserDialog to get the folder selected by the user.
After that, you've to just concatenate together the folder and the filename and pass it to the Save method.

bmpScreenshot.Save(folder + "\\MyScreenshot.png", ImageFormat.Png);


Well that does not work.. Then I get an GDI+ error or something.. :\
Was This Post Helpful? 0
  • +
  • -

#11 elbielefeld   User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 217
  • Joined: 18-May 10

Re: saveFileDialog

Posted 27 May 2010 - 04:19 PM

Make sure you have access rights and the folder exists.
Was This Post Helpful? 0
  • +
  • -

#12 Garnaal   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 64
  • Joined: 04-September 09

Re: saveFileDialog

Posted 27 May 2010 - 11:41 PM

Well, I've got it working now.

this is what I got!
                this.Hide();
                bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
                bmpScreenshot.Save(saveScreenshot.InitialDirectory + "\\" + saveScreenshot.FileName, ImageFormat.Png);
                this.Show();


This post has been edited by Garnaal: 27 May 2010 - 11:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1