Unknow File Format - How can i solve it???

  • Thread starter Thread starter Thomaz Pereira
  • Start date Start date
T

Thomaz Pereira

Hi;
I use the method below to save the an image showed in a
Picture Box using the SaveFileDialog.

protected void SaveImage()
{
try
{
Stream stream = File.OpenWrite
(this.CaminhoImagem);
using (StreamWriter writer = new StreamWriter
(stream))
{
writer.Write (this.pctImagem.Image.Clone ());
}
}
catch (IOException ex)
{
MessageBox.Show (ex.Message, "Harpia - Erro de
Gravação",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}//final do metodo

The method running very well and don't show me any error.
Is impossible to open the saved image because the image
format is wrong. Always i see the message: "UNKNOWN FILE
FORMAT"
How can i solve this problem???
 
Thomaz Pereira said:
I use the method below to save the an image showed in a
Picture Box using the SaveFileDialog.

protected void SaveImage()
{
try
{
Stream stream = File.OpenWrite
(this.CaminhoImagem);
using (StreamWriter writer = new StreamWriter
(stream))
{
writer.Write (this.pctImagem.Image.Clone ());
}
}

You're using a StreamWriter, which is designed for character data - but
you want to write binary data. Why have you created a StreamWriter at
all? Further, you're basically writing the result of Image.ToString(),
which I can't see being particularly helpful.

I suggest you use pctImagem.Image.Save instead.
 
HI Thomas,

I posted the answer in your other post.
It's a lot simpler that this, all you have to do is a
this.pctImagem.Image.Save( .... );

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Hi;
I use the method below to save the an image showed in a
Picture Box using the SaveFileDialog.

protected void SaveImage()
{
try
{
Stream stream = File.OpenWrite
(this.CaminhoImagem);
using (StreamWriter writer = new StreamWriter
(stream))
{
writer.Write (this.pctImagem.Image.Clone ());
}
}
catch (IOException ex)
{
MessageBox.Show (ex.Message, "Harpia - Erro de
Gravação",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}//final do metodo

The method running very well and don't show me any error.
Is impossible to open the saved image because the image
format is wrong. Always i see the message: "UNKNOWN FILE
FORMAT"
How can i solve this problem???
 
Back
Top