将div保存为文件夹中的图像

时间:2015-06-29 07:37:17

标签: c#

如何将div保存为同一文件夹中的图像  我正在使用c#。在下面的代码中,图像没有保存到文件夹,但是它正在下载,名称为html.png。请帮忙

protected void ExportToImage(object sender, EventArgs e)
{
    string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
    byte[] bytes = Convert.FromBase64String(base64);
    Response.Clear();
    Response.ContentType = "image/png";
    Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
    Response.Buffer = true;
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.BinaryWrite(bytes);
    Response.End();
}

1 个答案:

答案 0 :(得分:0)

好的,你有几个步骤,

  1. 创建一个名为img的字节数组,从字符串转换 之后,您将所有字节写入您的位置并使用它发送img。 img是字节数组。
  2. 您使用所需参数创建img_converter,有关图像转换器的更多信息在awnser底部提供 然后将所有字节写入文件并将bytes数组作为参数。
  3. 我认为其余部分非常简单,因为这些功能已经告诉了他们正在做什么。

    注意在bytes数组中输入你的html代码

    1.
    byte[] img = Convert.FromBase64String(s);
    System.IO.File.WriteAllBytes(@"C:\image.bmp", img);
    
    2.
    ImageConverter img_converter = new ImageConverter();
    byte[] bytes = (byte[])img_converter.ConvertTo(<strong class="highlight">image</strong>, typeof(byte[]));  
    File.WriteAllBytes(savefil.FileName, bytes);
    
    3.
    var imageBytes = File.ReadAllBytes("bitmap.bmp");
    var image = imageBytes.ToImage();
    image.Save("output.bmp");
    
    4.1 from some file:
    Image.Save(@"FilePath", ImageFormat.Jpeg);
    
    
    4.2.
    Image bitmap = Image.FromFile("C:\\MyFile.bmp");
    bitmap.Save("C:\\MyFile2.bmp");  
    
    5. from pictureBox:
    pictureBox1.Image.Save(@"path + imageName",ImageFormat.Jpeg);
    

    Save image in folder - msdn

    ImageConverter Methods