1

我使用 savedialogfile 保存一个 png 文件。但我想将它保存在应用程序 IMG 文件夹中。我的代码如下:

if (lastSnapshot != null)//writableBitmap object lastSnapshot
        {
            var dlg = new SaveFileDialog();
            dlg.DefaultExt = ".png";
            dlg.Filter = "PNG File|*.png";
            if (dlg.ShowDialog() == true)
            {
                using (var pngStream = GetPngStream(lastSnapshot))//return Stream type 
                using (var file = dlg.OpenFile())
                {
                    byte[] binaryData = new Byte[pngStream.Length];
                    long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);
                    file.Write(binaryData, 0, (int)pngStream.Length);
                    file.Flush();
                    file.Close();
                }
            }
        }

怎么做?我会感谢任何会帮助我的人。提前致谢。

我的相邻问题

4

2 回答 2

0
if (lastSnapshot != null)//writableBitmap object lastSnapshot
{
     using (var pngStream = GetPngStream(lastSnapshot))//return Stream type 
     using (var file = File.Create(Path.Combine("ImageFolder", "ImageName.png")))
     {
         byte[] binaryData = new Byte[pngStream.Length];
         long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);
         file.Write(binaryData, 0, (int)pngStream.Length);
     }
}
于 2012-11-28T07:10:49.430 回答
0

假设 ASP.net...

您需要使用HttpServerUtility.MapPath来计算服务器上路径的位置,并可能调整该文件夹的权限以允许 IIS 在那里写入。

var filePath = Server.MapPath("images\\myFile.png");
using (var file = File.Create(filePath))
{
  pngStream.Copy(file);
}
于 2012-11-28T07:17:46.703 回答