Reputation: 60871
what is the best way to save an image of a control?
currently i am doing this:
chart1.SaveImage(ms, ChartImageFormat.Bmp);
Bitmap bm = new Bitmap(ms);
how would i then prompt the user with a windowsavedialogue and save the BMP to a specific location?
if this is not the best way to do this please suggest a different way
Upvotes: 0
Views: 783
Reputation: 19872
Do this:
SaveFileDialog dlg = new SaveFileDialog();
// ... add your dialog options
DialogResult result = dlg.ShowDialog(owner);
if(result == DialogResult.OK)
{
bm.Save(dlg.FileName);
}
Upvotes: 0
Reputation: 52675
Daok has a nice answer for this.
Adapting Daok's code to change the extension Filter gives you this
chart1.SaveImage(ms, ChartImageFormat.Bmp);
Bitmap bm = new Bitmap(ms);
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments;
saveFileDialog1.Filter = "Your extension here (*.bmp)|*.*" ;
saveFileDialog1.FilterIndex = 1;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
bm.Save (saveFileDialog1.FileName);//Do what you want here
}
Upvotes: 2
Reputation: 15242
You could prompt them with a SaveFileDialog
that would allow them to choose the path and file name and file type where they want to save the file.
Then you just need to write the bmp to a file
Upvotes: 0