使用Handler.ashx获取图像
Getting an image using Handler.ashx
我目前正在做一个学校项目,我不确定返回了什么以及如何使数据可用。这是代码:
Default.aspx
function GetImage(id) {
//step k. - code here
xmlHttpObj = CreateXmlHttpRequestObject();
if (xmlHttpObj) {
xmlHttpObj.open("GET", "Handler.ashx?id=" + id, true);
xmlHttpObj.send(null);
var image = document.getElementById("ProductImage");
//the response contains an array of 5419 index
}
}
句柄.ashx
public void ProcessRequest (HttpContext context)
{
int id;
if (context.Request.QueryString["id"] != null)
{
id = Convert.ToInt32(context.Request.QueryString["id"]);
context.Response.ContentType = "image/jpeg";
byte[] bufferImg = GetImage(id);
context.Response.OutputStream.Write(bufferImg, 0, bufferImg.Length);
}
}
GetImage(int id)返回"(byte[]).cmd.ExecuteScaler();",我真的不确定该如何处理传递回来的信息。我想是图像本身吧?任何帮助都将不胜感激。谢谢
为什么不尝试
function GetImage(id) {
document.getElementById("ProductImage").src="Handler.ashx?id=" + id;
}
相关文章:
- 获取ajax加载的图像的大小
- 点击(右键点击)使用传单地图库获取图像覆盖的像素坐标
- 如何使用javascript和xpath获取图像src
- 如何使用javascript从文件夹中获取图像并发布直接链接
- 如何使用Pixijs获取在加载的精灵表资产中定义的图像
- 如何从 javascript 中可能具有一个或多个图像的字符串中仅获取图像名称
- 获取图像节点js的主色
- 获取图像的平均外部像素颜色
- 使用asp.net FileUpload时从javascript获取图像宽度和高度
- 如何获取显示在谷歌搜索右侧的图像链接
- CodeIgniter:用于获取包括图像在内的值的控制器
- jQuery:获取图像加载错误的详细信息
- 如何使用php和javascript获取网页中显示图像的路径
- 使用回调获取图像像素数据
- 使用JavaScript从外部图像获取颜色
- 将完整路径图像获取到输入文件中
- 如何利用织物画布上的背景图像获取绘图路径中的图像
- 无法将图像加载到画布中并为该图像获取base64编码
- Android从内部图像获取ImageData()-SECURITY_ERR:DOM异常18
- 将html转换为图像(获取dom的快照)