如何将位图图像放入图像服务器控件 [英] How to get Bitmap image into an Image server control

查看:58
本文介绍了如何将位图图像放入图像服务器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

谁能告诉我如何将返回的位图图像获取到图像服务器控件.
我的代码如下.如何将其返回到图像服务器控件?


我遇到的问题是,当直接将返回的位图图像直接显示到网页上时,所有其他HTML和服务器控件都变得不可见.只有位图图像可见,我想避免这种情况,因此我应该在图像中显示位图服务器控制...


Graphics obj_Graphics;
  Bitmap obj_Bitmap = new Bitmap(500, 500);
  obj_Graphics = Graphics.FromImage(obj_Bitmap);


用于绘制图像的代码为:

System.Web.HttpContext.Current.Response.ContentType = "image/jpeg";
        obj_Bitmap.Save(System.Web.HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);
        obj_Bitmap.Dispose();
        obj_Graphics.Dispose();
        System.Web.HttpContext.Current.Response.End();

        return obj_Bitmap;



在此先感谢

解决方案

您需要将页面的呈现和图像的呈现分为两个页面".您不能在同一操作中同时执行这两个操作.

这是正在发生的事情:

用户的浏览器使用HTTP GET例如获取http://mabel.ca/
服务器的工作是使用您的Web表单创建的HTML文档来回复此请求.

您在上方所做的是回复图片而不是html.
您需要做的是使用有效的HTML进行回复,并且该HTML应该在要创建的另一页上包含有效的img标签,例如< img src ="http://mabel.ca/title.aspx" alt =标题图片"/>

请记住,网页只是一个HTML文档.对于每个图像,样式表,Flash动画等,客户端的浏览器必须发出单独的GET请求.

这个新页面的工作仅是渲染图像.浏览器将知道它是一个图像(a),因为img标签告诉它期望有一个图像; (b)因为您已将HTTP设置为Content-Type标头; (c)因为如果其他所有方法都失败,则浏览器非常擅长猜测内容类型.

所以:
1.制作一个仅呈现图像的页面.
2.制作一个内容页面.它应该包含一个链接到#1的img标签. WriteBytes或Response.WriteFile(取决于它是否是文件系统上的文件)将信息传递回去.您还需要设置响应标头以说它是图像.


Hi there,

Can anyone tell me how to get the returned bitmap image to an Image server control.
My code is below. How can I return it to an Image server control?


The problem I encountered is, When displaying the returned Bitmap Image directly to the web page all other Html as well as Server controls become invisble.Only bitmap image is visible.I want to avoid that.So I supposed to display the bitmap in an Image server control...


Graphics obj_Graphics;
  Bitmap obj_Bitmap = new Bitmap(500, 500);
  obj_Graphics = Graphics.FromImage(obj_Bitmap);


Code for Drawing Image as:

System.Web.HttpContext.Current.Response.ContentType = "image/jpeg";
        obj_Bitmap.Save(System.Web.HttpContext.Current.Response.OutputStream, ImageFormat.Jpeg);
        obj_Bitmap.Dispose();
        obj_Graphics.Dispose();
        System.Web.HttpContext.Current.Response.End();

        return obj_Bitmap;



Thanks in advance

解决方案

You need to separate rendering of your page and rendering of the image into two "pages". You cannot do both of them in the same operation.

Here is what is happening:

The user''s browser requests your web page using HTTP GET e.g. GET http://mabel.ca/
The server''s job is to reply to this request with the HTML document created by your web form.

What you are doing above is replying with the image instead of the html.
What you need to do is reply with valid HTML and that HTML should include a valid img tag to another page that you''ll create e.g. <img src="http://mabel.ca/title.aspx" alt="title image"/>

Remember a web page is only a single HTML document. For every image, stylesheet, Flash animation, etc the client''s browser must make a separate GET request.

The job of this new page is ONLY to render the image. The browser will know it''s an image (a) because the img tag tells it to expect an image; (b) because you''ve set the HTTP the Content-Type header; (c) because if all else fails, browsers are pretty good at guessing content types.

So:
1. Make a page that just renders your image.
2. Make a page for your content. It should include an img tag that links to #1.


Just to add, your second page, will ideally take an id on the URL to look up the image bytes, then use Response.WriteBytes or Response.WriteFile, depending on if it''s a file on the file system, to pass that information back. You also need to set the response header to say it''s an image.


这篇关于如何将位图图像放入图像服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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