[英]How can I assign a bitmap to a Image control in asp.net using c#?
I have an asp.net file as follows: 我有一个asp.net文件,如下所示:
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
<div>
<asp:Image ID="Image1" runat="server" />
</div>
</form>
I want to set the Image1 in the c# using the following code: 我想使用以下代码在c#中设置Image1:
protected void Button1_Click(object sender, EventArgs e)
{
Bitmap oBmp1 = new Bitmap(460, 60);
Graphics oGrp1 = Graphics.FromImage(oBmp1);
Color ocolor = new Color();
ocolor = Color.Yellow;
SolidBrush oBrush = new SolidBrush(ocolor);
SolidBrush oBrushWrite = new SolidBrush(Color.White);
oGrp1.FillRectangle(oBrush, 100, 25, 500, 75);
Response.ContentType = "image/jpeg";
oBmp1.Save(Response.OutputStream, ImageFormat.Jpeg);
}
How can I directly set the image1 in c# after I generate the bitmap without saving bitmap as an image file? 生成位图后如何在c#中直接设置image1而又不将位图另存为图像文件?
Your above solution won't work. 您上面的解决方案无法正常工作。
You have to create a separate handler (.ashx) to return image. 您必须创建一个单独的处理程序(.ashx)以返回图像。 You will have to pass appropriate parameters as query string and link it to your Image control 您将必须传递适当的参数作为查询字符串,并将其链接到Image控件。
See this http://www.4guysfromrolla.com/articles/042209-1.aspx 看到这个http://www.4guysfromrolla.com/articles/042209-1.aspx
您可以将位图另存为任何文件夹中的图像文件,并使用图像控件找到图像文件路径以显示图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.