簡體   English   中英

在asp.net中從網頁上的圖像讀取流

[英]Reading streams from image on a web page in asp.net

我在asp.net網站的圖像控件中綁定了圖像。

我正在使用C#開發它。 下面的代碼綁定圖像。

 byte[] imageBytes = System.IO.File.ReadAllBytes("filepath");
 string base64String = Convert.ToBase64String(imageBytes, 0, imageBytes.Length);
 this.testImage.Src = "data:image/jpeg;base64," + base64String;

現在,我想在另一個事件中從該圖像控件(testImage)中獲取流。 我不想將圖像保存在任何服務器路徑中。

我怎樣才能做到這一點?

提前致謝。

嘗試這個:

WebClient webClient = new WebClient();
Image img = Image.FromStream(webClient.OpenRead(path));
webClient.Dispose();

僅當映像不是您硬盤上的文件時,才適用。

如果映像位於硬盤上,則應這樣做:

Image img = Image.FromFile(path);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM