我的代码:
string editingFileName = @"D:\about.gif";
string sDirectory = @"D:\aboutNew.gif";
FileStream fs = new FileStream(editingFileName,FileMode.Open,FileAccess.Read); 
StreamReader streamR = new StreamReader(fs);
Int32 FileLength = Convert.ToInt32(new System.IO.FileInfo(editingFileName).Length);
char[] sbuff = new char[FileLength];
streamR.Read(sbuff,0,FileLength);
if(File.Exists(sDirectory))
{
new System.IO.FileInfo(sDirectory).Delete();
}
FileStream Winput = new FileStream(sDirectory,FileMode.CreateNew,FileAccess.Write); 
StreamWriter streamWriter = new StreamWriter( Winput );
streamWriter.Write(sbuff,0,FileLength);
streamWriter.Flush();
现在D:\aboutNew.gif文件打开不出现图象我想得到图象
我现在是技术上不知道如何实现。
请大家帮忙了

解决方案 »

  1.   

    char[] sbuff = new char[FileLength];
    streamR.Read(sbuff,0,FileLength);这里的问题,sbuff的长度并不和FileLength相等,按这种写法sbuff的后半段都是空的,再写到新文件,新文件会比原文件大为什么不用
    File.Copy(editingFileName,sDirectory)
      

  2.   

    不能用COPY 
    因我的图象是远程传过来的一个XML文件中一个节点中的值,其在节点中应该表示成什么形式还未确定下来,我想应该是字符串形式吧,在取时再转换成stream(不知可否,还请高手们帮忙)。然后我接收这个XML文件,取出那一个节点,然后将其存为一个文件(不存入数据库的原因是担心文件太多,会影响数据库性能,所就保存到一个目录下,在数据库中只存文件路径信息)
    现在我是试一下读出一个图象文件,想用重写文件或其它形式生成一个新文件。有什么好方法呀,急!!!
      

  3.   

    用一个byte[]传递,或者是字符串传过来转byte[],然后MemoryStream ms=new MemoryStream(buffer);
    Image image=Image.FromStream(ms,true);
    image.Save(sDirectory,System.Drawing.Imaging.ImageFormat.Gif);