Пример #1
0
 /// <summary>
 /// 把图像文件转化为字节数组
 /// </summary>
 /// <param name="imageFile"></param>
 /// <returns></returns>
 public static byte[] Image2Bytes(string imageFile)
 {
     using (var ms = new MemoryStream())
     {
         using (Image img = Image.FromFile(imageFile))
         {
             img.Save(ms, GetImageFormat(imageFile));
             return(StreamUtility.Stream2Bytes(ms));
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 把图像转化为字节数组
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public static byte[] Image2Bytes(Image img)
        {
            if (img == null)
            {
                return(null);
            }

            using (Stream s = new MemoryStream())
            {
                img.Save(s, ImageFormat.Jpeg);
                return(StreamUtility.Stream2Bytes(s));
            }
        }