本页面二进制流输出图片

asd100230520 2012-10-24 04:19:00
有个页面 页面上有些信息(一些文本信息) 我在Page_Load
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\Documents and Settings\Developer\桌面\94f6b0begw1dnw55ez8dbg.gif", FileMode.Open, FileAccess.Read);
int fslength=(int)fs.Length;
byte[] bimg = new byte[fslength];
fs.Read(bimg, 0, fslength);
fs.Close();
Response.ClearContent();
Response.ContentType = "image/gif";
Response.OutputStream.Write(bimg, 0, fslength);
Response.End();
}
用二进制流输出图片 但是访问这个页面的时候显示就只有这张图片 页面上本来的东西就不见了 求大神帮帮忙 怎么才显示本页面的所有信息及输出的图片
...全文
347 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
insus 2012-10-26
  • 打赏
  • 举报
回复
格桑花 2012-10-26
  • 打赏
  • 举报
回复
把你输出二进制图片的代码放在单独的页面里面用来输出图片。例如页面名称为Image.aspx。
再绑定到空间上 <img id="image" src="Image.aspx" />
宝_爸 2012-10-26
  • 打赏
  • 举报
回复
页面的Type都改了Response.ContentType = "image/gif"; 只能输出图片了。
asd100230520 2012-10-25
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

public class ConvertType
{

public static byte[] StreamToBytes(Stream stream)
{

byte[] bytes = new byte[stream.Length];

stream.Read(bytes, 0, byt……
[/Quote]
试了还是不行 只有页面只有输出的图片 文本信息没有了
lw_881020 2012-10-25
  • 打赏
  • 举报
回复
public class ConvertType
{

public static byte[] StreamToBytes(Stream stream)
{

byte[] bytes = new byte[stream.Length];

stream.Read(bytes, 0, bytes.Length);

// 设置当前流的位置为流的开始

stream.Seek(0, SeekOrigin.Begin);

return bytes;

}
}[Quote=引用 5 楼 的回复:]
引用 3 楼 的回复:

把Response.OutputStream.Write(bimg, 0, fslength);
改成Response.BinaryWrite(ConvertType.StreamToBytes(fs));


ConvertType 是哪个命名空间的啊?
[/Quote]
asd100230520 2012-10-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

Response.ClearContent();

因为你这里重写类响应流。即使上面没有ClearContent也不行的。
响应流已经被改掉了。

为什么不直接绑定图片呢?路径都有。
[/Quote]

这个路径只是做测试用的,实际上要去数据库里面读取的
wanghui0380 2012-10-25
  • 打赏
  • 举报
回复
有关base64的解法

你可以看
http://staratsky.iteye.com/blog/314651

不过你应该注意到了,这种解法太不划算了,html被人为“增肥”
wanghui0380 2012-10-25
  • 打赏
  • 举报
回复
方法用错了,你写方法本身就只能输出一张图片而不是整个html

如果是本页连图片带html一起输出的应该是把图片流用base64编码以后,加到img标签里面,不过我们不建议如此,无端让html变胖了

你应该如10楼那样,采用另外一个页面输出才是正解
mngzilin 2012-10-25
  • 打赏
  • 举报
回复
<img src="a.aspx" />
--------------------------
一个图片就要求一个响应的http输出流
asd100230520 2012-10-24
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

C# code


Bitmap bitmap = new Bitmap(stream);

Image bufferImage = bitmap as Image ;
[/Quote]

Image bufferImage = bitmap as Image;
无法通过引用转换
asd100230520 2012-10-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

把Response.OutputStream.Write(bimg, 0, fslength);
改成Response.BinaryWrite(ConvertType.StreamToBytes(fs));
[/Quote]

ConvertType 是哪个命名空间的啊?
XBodhi. 2012-10-24
  • 打赏
  • 举报
回复


Bitmap bitmap = new Bitmap(stream);

Image bufferImage = bitmap as Image ;

lw_881020 2012-10-24
  • 打赏
  • 举报
回复
把Response.OutputStream.Write(bimg, 0, fslength);
改成Response.BinaryWrite(ConvertType.StreamToBytes(fs));
wuyq11 2012-10-24
  • 打赏
  • 举报
回复
image.syc="1.gif";显示
或嵌套img src="xx.aspx?type=image">
Page_Load:
if(Request.QueryString["type"]=="image")
{
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
Response.End();
}
Hauk 2012-10-24
  • 打赏
  • 举报
回复
Response.ClearContent();

因为你这里重写类响应流。即使上面没有ClearContent也不行的。
响应流已经被改掉了。

为什么不直接绑定图片呢?路径都有。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧