zoukankan      html  css  js  c++  java
  • C#中Image类与byte[]之间的转换

    //将image转化为二进制 
            public byte[] GetByteImage(Image img)
            {
                byte[] bt = null;
                if (!img.Equals(null))
                {
                    using (MemoryStream mostream = new MemoryStream())
                    {
                        Bitmap bmp = new Bitmap(img);
                        bmp.Save(mostream, System.Drawing.Imaging.ImageFormat.Bmp);//将图像以指定的格式存入缓存内存流
                        bt = new byte[mostream.Length];
                        mostream.Position = 0;//设置留的初始位置
                        mostream.Read(bt, 0, Convert.ToInt32(bt.Length));
                    }
                }
                return bt;
            }
    
    反之,将byte[]转化为Image类型数据:
            public static Image GetImageByBytes(byte[] bytes)
            {
                Image photo = null;
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    ms.Write(bytes, 0, bytes.Length);
                    photo = Image.FromStream(ms, true);
                }
                return photo;
            }
  • 相关阅读:
    spark
    mongdb
    redis
    mysql
    kylin
    kafka
    hadoop+hive+hbase+kylin
    git
    elasticsearch
    clickhouse
  • 原文地址:https://www.cnblogs.com/zhangwei99com/p/7756732.html
Copyright © 2011-2022 走看看