.NET中將圖片文件流轉(zhuǎn)成Base64字符串的實(shí)現(xiàn)
不太好意思啊,這篇隨筆有點(diǎn)短,因工作上需要用WCF調(diào)用有一個別的語言開發(fā)的服務(wù)接口!而涉及到圖片傳輸?shù)牟糠种蛔寕鰾ase64字符串。
所以下面簡短的代碼即可用于將客戶瀏覽器上傳過來的圖片文件轉(zhuǎn)換成Base64字符串
//上傳控件.PostedFile.InputStream
public void EncodingBase64_Image(Stream stream, ref string base64Str)
{
using (BinaryReader binReader = new BinaryReader(stream))
{
byte[] bytes = binReader.ReadBytes(Convert.ToInt32(stream.Length));
base64Str = Convert.ToBase64String(bytes);
}
}
結(jié)束。。



浙公網(wǎng)安備 33010602011771號