Hi, Were is the problem in code.. i am trying to read the .gif file and writing to the another .gif, if i do so... the newly cretaed .gif file will not show correct image insted junk image comes were is the mistake in code.
private void ReadFile()
{
StreamReader MyReader = new StreamReader(@"C:\\Users\\admin\\Desktop\\apache_pb22_ani.gif");
string ReadFile= MyReader.ReadToEnd();
MyReader .Close ();
StreamWriter MYWriter = new StreamWriter(@"C:\\Hi.gif");
MYWriter.Write(ReadFile);
MYWriter.Close();
//throw new NotImplementedException();
}
if i read image from server and if i write to the image file also same problem appears, what is the problem... code of reading image from server and writing is here
StringBuilder sb = new StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://10.10.21.178/Untitled.jpg");
// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
StreamWriter FileWriter = new StreamWriter("C:\\Testing.jpg");
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text.
// Not needed if you'll get binary content.
tempString = Encoding.ASCII.GetString(buf, 0, count);
FileWriter.Write(tempString);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0); // any more data to read?
FileWriter.Close();
// print out page source
// Console.WriteLine(sb.ToString());
//throw new NotImplementedException();
}