I am not talking about easier code.
Do you know how many things are happen in one small line
System.Drawing.Image img = System.Drawing.Image.FromStream(remoteStream);
If image is JPEG then stream is decompressed with fairly expensive
arithmetic operations.
Then you do opposite operation with this line
img.Save( filename, System.Drawing.Imaging.ImageFormat.Jpeg );
Plus you are loosing on image quality. This is what JPEG format is about. It
compresses image by loosing quality.
Open up any tool like Photoshop and it will allow you to choose the
compression level.
Plus if you download image with the size 2048x1024 do you know how many
bytes it's going to eat when you decompress it.
2048*1024*4 = 8 Megabytes.
So conclusion: it's just plain bad code.
-------------------------
Attempt to do it with StreamReader and to do this
String t = stream .ReadToEnd();
probably even worse (not sure which one worse actually).
Never convert to string binary data.
---------------------------
The best solution to save stream to file would be something like this
Stream st = WebResponse.GetResponseStream();
using(Stream fs = File.Open(path, FileMode.Create) )
{
byte []buf = new byte[1000];
int iRead = 0;
do
{
iRead = st.Read(buf, 0, buf.lengh);
if( iRead > 0 )
fs.Write(buf, 0, iRead);
} while(iRead > 0 )
}
Is it more than those 2 lines you wrote: no
Is it much better code : Yes.
PS: you can throw out all your MCPMBDBA titles.
George.
"mxdev, MCDBA, MCPD, MCITP, MCP" <mxdev, MCDBA, MCPD, MCITP,
(e-mail address removed)> wrote in message