Response.BinaryWrite v/s Response.Write [英] Response.BinaryWrite v/s Response.Write

查看:68
本文介绍了Response.BinaryWrite v/s Response.Write的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个HTML页面,提交时我叫Hanlder(ASHX).

在处理程序中,我正在生成图像.该映像不应保存在客户端/服务器计算机上.因此,我将图像保存在MemoryStream中.之后,我需要显示带有一些详细文本的图像.

我可以使用 Response.BinaryWrite()方法显示图像.但是当我尝试使用 Response.Write()编写文本时,文本不会出现.

Hi Everyone,

I have one HTML page, on submitting I am calling a Hanlder (ASHX).

In handler, I am generating an image. That image should not be saved on client/server machine. So I saved the Image in MemoryStream. After that I need to display that image with some detail text.

I could display the Image with Response.BinaryWrite() method.. but when I try to write text with Response.Write(), text does not appear.

Dim ms As MemoryStream = New MemoryStream()
BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
context.Response.ContentType = "image/jpeg"
context.Response.Clear()
context.Response.BinaryWrite(ms.ToArray())
context.Response.Write("<BR> HI <BR>")



任何想法... !!



Any ideas... !!

推荐答案

PS:下面的代码在C#中.
请执行以下步骤来解决它.

第1步:新建1个页面Test.aspx

Test1.aspx.cs后面的代码
PS:This below code is in C#.
Please do the following steps to resolve it.

Step1: Take 1 new Page Test.aspx

Code behind Test1.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Image BCImage = new  System.Drawing.Bitmap(@"C:\test.jpg");
MemoryStream ms = new MemoryStream();
BCImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "image/jpeg";
Response.Clear();
Response.BinaryWrite(ms.ToArray());
}



步骤2:在您的处理程序页面上



Step2: On your handler page

Image img = new Image();
img.ImageUrl = "~/Test1.aspx";
panel1.Controls.Add(img);
Response.Write("<BR> HI <BR>");



然后它将向您显示事物(图像和文本/html内容)

如果这对您有帮助,那么请投票并接受回答:rose:



Then it will show you both the things(Image and text/html content)

If this helped you then please Vote and accept as Answer :rose:


您已经告诉浏览器期望图像类型带有
You have told the browser to expect a image of type jpeg with
context.Response.ContentType = "image/jpeg"


因此,它不希望您也发送纯文本/html文本,因此它将要么忽略它,要么将其与图像数据合并,以任何一种方式都不会显示它.


so it is not expecting you to also send plain/html text, so it will either ignore it or maybe lump it in with the image data, either way it will not display it.


这篇关于Response.BinaryWrite v/s Response.Write的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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