• Image <=> byte[]


            private Byte[] Image2Bytes(string imagefilename)

            {

                System.IO.FileStream stream = new System.IO.FileStream(imagefilename, System.IO.FileMode.OpenOrCreate);

                byte[] bytes = new byte[stream.Length];

                if (stream.CanRead)

                {

                    stream.Read(bytes, 0, (int)stream.Length);

                }

                stream.Close();

                return bytes;

            }

     

            private Byte[] Image2Bytes(Image image)

            {

                byte[] Ret=null;

                try

                {

                    using (MemoryStream ms = new MemoryStream())

                    {

                        image.Save(ms, ImageFormat.Jpeg);

                        Ret = ms.ToArray();

                    }

                }

                catch (Exception) { throw; }

                return Ret;

            }

     

            private Image Bytes2Image(byte[] bytes)

            {

                MemoryStream ms2 = new MemoryStream(bytes, 0, bytes.Length);

                ms2.Write(bytes, 0, bytes.Length);

                return Image.FromStream(ms2, true);

            }

  • 相关阅读:
    springboot-pom文件报错问题
    php-session永不过期
    linux mysql 配置
    jmeter
    性能指标
    ab
    php--xdebug调试
    logstash6-mysql同步数据到es
    php--宝塔环境
    linux-centos7安装错误解决
  • 原文地址:https://www.cnblogs.com/yansc/p/1402836.html
Copyright © 2020-2023  润新知