EDN Admin
Well-known member
Hi,
I am a beginner working on my first C# app using a tutorial w/ source files (( http://howtoideas.net/how-to-crop-an-image-using-c http://howtoideas.net/how-to-crop-an-image-using-c and
http://howtoideas.net/wp-content/uploads/C%20Sharp%20Source%20Codes/Image%20Processing%20-%20HowToIdeas.rar
http://howtoideas.net/wp-content/uploads/C%20Sharp%20Source%20Codes/Image%20Processing%20-%20HowToIdeas.rar ) to build my own version.
Im stuck trying to adapt the Image Editor to save additional file types. After cropping a photo, the sample version is set up to save only JPEG files. I would like to give the user the option to save JPEG, PNG, GIF, BMP. From researching online, it
seems that PNG may require a different saving mechanism than the others.
The current code to save, using a menu strip "save" item is:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void saveToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
SaveFileDialog sfd = <span style="color:Blue; new SaveFileDialog();
sfd.Filter = <span style="color:#A31515; "JPEG|*.JPG|PNG|*.PNG|GIF|*.GIF|BMP|*.BMP|All files (*.*)|*.*";
<span style="color:Blue; if (sfd.ShowDialog() == DialogResult.OK)
{
<span style="color:Blue; try
{
<span style="color:Blue; using (Bitmap bitmap = <span style="color:Blue; new Bitmap(pictureBox1.Image))
{
bitmap.Save(sfd.FileName, ImageFormat.Jpeg);
}
MessageBox.Show(<span style="color:#A31515; "Picture Saved Successfully.");
}
<span style="color:Blue; catch (Exception ex)
{
MessageBox.Show(<span style="color:#A31515; "An Error has occured: n" + ex.Message);
}
}
}
[/code]
This only successfully saves JPEG.
What code would add ability to save all of these image file types including PNG?
Any help appreciated.
Kind Regards,
saratogacoach
View the full article
I am a beginner working on my first C# app using a tutorial w/ source files (( http://howtoideas.net/how-to-crop-an-image-using-c http://howtoideas.net/how-to-crop-an-image-using-c and
http://howtoideas.net/wp-content/uploads/C%20Sharp%20Source%20Codes/Image%20Processing%20-%20HowToIdeas.rar
http://howtoideas.net/wp-content/uploads/C%20Sharp%20Source%20Codes/Image%20Processing%20-%20HowToIdeas.rar ) to build my own version.
Im stuck trying to adapt the Image Editor to save additional file types. After cropping a photo, the sample version is set up to save only JPEG files. I would like to give the user the option to save JPEG, PNG, GIF, BMP. From researching online, it
seems that PNG may require a different saving mechanism than the others.
The current code to save, using a menu strip "save" item is:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; private <span style="color:Blue; void saveToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
SaveFileDialog sfd = <span style="color:Blue; new SaveFileDialog();
sfd.Filter = <span style="color:#A31515; "JPEG|*.JPG|PNG|*.PNG|GIF|*.GIF|BMP|*.BMP|All files (*.*)|*.*";
<span style="color:Blue; if (sfd.ShowDialog() == DialogResult.OK)
{
<span style="color:Blue; try
{
<span style="color:Blue; using (Bitmap bitmap = <span style="color:Blue; new Bitmap(pictureBox1.Image))
{
bitmap.Save(sfd.FileName, ImageFormat.Jpeg);
}
MessageBox.Show(<span style="color:#A31515; "Picture Saved Successfully.");
}
<span style="color:Blue; catch (Exception ex)
{
MessageBox.Show(<span style="color:#A31515; "An Error has occured: n" + ex.Message);
}
}
}
[/code]
This only successfully saves JPEG.
What code would add ability to save all of these image file types including PNG?
Any help appreciated.
Kind Regards,
saratogacoach
View the full article