如何创建页面html的图像 [英] how create image of page html

查看:98
本文介绍了如何创建页面html的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我正在使用此代码将html页面转换为图像
但我在行中出现错误
(System.Drawing.Image img = System.Drawing.Image.FromStream(ms);)

错误是:(参数无效.)


完整代码在这里:

hi

I am using this code to coonvert page html into image
but i am getting error in line
(System.Drawing.Image img = System.Drawing.Image.FromStream(ms);)

Error is : (Parameter is not valid.)


full code here:

string content = "";
System.Net.WebRequest webRequest = WebRequest.Create("http://localhost:58534/EFTestApp/ScreenShot.aspx");
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));
content = sr.ReadToEnd().Trim();
//save to file
byte[] bytesToEncode = Encoding.UTF8.GetBytes(content);
string encodedText = Convert.ToBase64String(bytesToEncode);

byte[] b = Convert.FromBase64String(encodedText);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(b, 0, b.Length))
{
    System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
    img.Save(Server.MapPath("screenshot/myscreenshot.bmp"), System.Drawing.Imaging.ImageFormat.Jpeg);
}

推荐答案

我认为byteArrayIn不包含有效的图像数据.您应该尝试设置一个断点并逐步执行.检查丢失图像数据的位置.

请参考 Image.FromStream方法(Stream,布尔值,布尔值) [ FromStream和参数无效" [ ^ ]
--Amit
As I think that byteArrayIn doesn''t contain valid image data. You should try putting a breakpoint and stepping over the lines. Check where you are losing your image data.

Refer Image.FromStream Method (Stream, Boolean, Boolean)[^].
And FromStream and the "Parameter is not valid"[^]
--Amit


这篇关于如何创建页面html的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆