欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C#中圖片、二進(jìn)制與字符串的相互轉(zhuǎn)換方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

本文實(shí)例講述了C#中圖片、二進(jìn)制與字符串的相互轉(zhuǎn)換方法。分享給大家供大家參考,具體如下:

protected void Button1_Click(object sender, EventArgs e)
{
  //圖片轉(zhuǎn)二進(jìn)制
  byte[] imageByte = GetPictureData(Server.MapPath("./uploadfile/111.png"));
  //二進(jìn)制轉(zhuǎn)換成字符串
  string picStr = Convert.ToBase64String(imageByte);
  //輸出字符串
  Response.Write(picStr);
  //字符串轉(zhuǎn)二進(jìn)制
  byte[] imageBytes = Convert.FromBase64String(picStr);
  //讀入MemoryStream對(duì)象
  MemoryStream memoryStream = new MemoryStream(imageBytes, 0, imageBytes.Length);
  memoryStream.Write(imageBytes, 0, imageBytes.Length);
  //二進(jìn)制轉(zhuǎn)成圖片保存
  System.Drawing.Image image = System.Drawing.Image.FromStream(memoryStream);
  image.Save(Server.MapPath("./uploadfile/222.png"));
}
/// <summary>
/// 二進(jìn)制流轉(zhuǎn)圖片
/// </summary>
/// <param name="streamByte">二進(jìn)制流</param>
/// <returns>圖片</returns>
public System.Drawing.Image ReturnPhoto(byte[] streamByte)
{
  System.IO.MemoryStream ms = new System.IO.MemoryStream(streamByte);
  System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
  return img;
}
/// <summary>
/// 圖片轉(zhuǎn)二進(jìn)制
/// </summary>
/// <param name="imagepath">圖片地址</param>
/// <returns>二進(jìn)制</returns>
public byte[] GetPictureData(string imagepath)
{
  //根據(jù)圖片文件的路徑使用文件流打開,并保存為byte[]
  FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重載方法
  byte[] byData = new byte[fs.Length];
  fs.Read(byData, 0, byData.Length);
  fs.Close();
  return byData;
}
/// <summary>
/// 圖片轉(zhuǎn)二進(jìn)制
/// </summary>
/// <param name="imgPhoto">圖片對(duì)象</param>
/// <returns>二進(jìn)制</returns>
public byte[] PhotoImageInsert(System.Drawing.Image imgPhoto)
{
  //將Image轉(zhuǎn)換成流數(shù)據(jù),并保存為byte[]
  MemoryStream mstream = new MemoryStream();
  imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);
  byte[] byData = new Byte[mstream.Length];
  mstream.Position = 0;
  mstream.Read(byData, 0, byData.Length);
  mstream.Close();
  return byData;
}

PS:這里小編再給大家推薦本站的一款圖片轉(zhuǎn)BASE64格式的在線轉(zhuǎn)換工具,非常具有實(shí)用價(jià)值:

在線圖片轉(zhuǎn)換BASE64工具:
http://tools.jb51.net/transcoding/img2base64

更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》及《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》

希望本文所述對(duì)大家C#程序設(shè)計(jì)有所幫助。

上一篇:C#模擬http 發(fā)送post或get請(qǐng)求的簡單實(shí)例

欄    目:C#教程

下一篇:C# IsDefined的問題

本文標(biāo)題:C#中圖片、二進(jìn)制與字符串的相互轉(zhuǎn)換方法

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/6458.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有