[英]C# :How can i set Memory stream as the asp.net image control's source property?
[英]How can I assign a bitmap to a Image control in asp.net using c#?
我有一個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>
我想使用以下代碼在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);
}
生成位圖后如何在c#中直接設置image1而又不將位圖另存為圖像文件?
您上面的解決方案無法正常工作。
您必須創建一個單獨的處理程序(.ashx)以返回圖像。 您將必須傳遞適當的參數作為查詢字符串,並將其鏈接到Image控件。
您可以將位圖另存為任何文件夾中的圖像文件,並使用圖像控件找到圖像文件路徑以顯示圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.