国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C# 將字節(jié)流轉(zhuǎn)換為圖片的實例方法

2020-01-24 03:33:54
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Drawing;
usingSystem.IO;
namespaceMicrosoft.Form.Base
{
    classImageToByte
    {
        /// <summary>
        /// 圖片轉(zhuǎn)換成字節(jié)流
        /// </summary>
        /// <param name="img">要轉(zhuǎn)換的Image對象</param>
        /// <returns>轉(zhuǎn)換后返回的字節(jié)流</returns>
        publicstaticbyte[] ImgToByt(Image img)
        {
            MemoryStream ms = newMemoryStream();
            byte[] imagedata = null;
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            imagedata = ms.GetBuffer();
            returnimagedata;            
        }
        /// <summary>
        /// 字節(jié)流轉(zhuǎn)換成圖片
        /// </summary>
        /// <param name="byt">要轉(zhuǎn)換的字節(jié)流</param>
        /// <returns>轉(zhuǎn)換得到的Image對象</returns>
        publicstaticImage BytToImg(byte[] byt)
        {
            MemoryStream ms = newMemoryStream(byt);
            Image img = Image.FromStream(ms);
            returnimg;
        }
        //
        /// <summary>
        /// 根據(jù)圖片路徑返回圖片的字節(jié)流byte[]
        /// </summary>
        /// <param name="imagePath">圖片路徑</param>
        /// <returns>返回的字節(jié)流</returns>
        privatestaticbyte[] getImageByte(stringimagePath)
        {
            FileStream files = newFileStream(imagePath, FileMode.Open);
            byte[] imgByte = newbyte[files.Length];
            files.Read(imgByte, 0, imgByte.Length);
            files.Close();
            returnimgByte;
        }
    }
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 那曲县| 东山县| 岳西县| 肥城市| 古田县| 盐源县| 神池县| 旬邑县| 三门县| 镇康县| 漳浦县| 河南省| 色达县| 得荣县| 惠安县| 婺源县| 西青区| 元氏县| 重庆市| 固阳县| 兴海县| 黄冈市| 文山县| 大城县| 阳春市| 沧源| 湖北省| 曲松县| 鸡西市| 十堰市| 随州市| 苍南县| 甘孜县| 德阳市| 益阳市| 赣榆县| 土默特右旗| 富顺县| 财经| 聂拉木县| 宿松县|