码迷,mamicode.com
首页 > Windows程序 > 详细

C#对图片的操作

时间:2015-06-15 16:13:06      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

1、根据图片路径返回字节

public static byte[] getImageByte(string imagePath)
{
    FileStream files = new FileStream(imagePath, FileMode.Open);
    byte[] imgByte = new byte[files.Length];
    files.Read(imgByte, 0, imgByte.Length);
    files.Close();
    return imgByte;
}
public static byte[] ImgToByt(Image img)
{
    MemoryStream ms = new MemoryStream();
    byte[] imagedata = null;
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    imagedata = ms.GetBuffer();
    return imagedata;
}

2、字节转图片

public static Image BytToImg(byte[] byt)
{
    MemoryStream ms = new MemoryStream(byt);
    Image img = Image.FromStream(ms);
    return img;
}

 

C#对图片的操作

标签:

原文地址:http://www.cnblogs.com/zxiong/p/4577024.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!