zoukankan      html  css  js  c++  java
  • 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);

            }

  • 相关阅读:
    HDU 6076
    HDU 6069
    ZOJ
    HDU
    斜率优化dp
    UVA 11752 The Super Powers
    poj 3761 bubble sort (排列组合)
    UVA 11174 Stand in a Line
    Caffe初学者第二部:Ubuntu16.04上安装caffe(CPU)+Matlab2014a+Opencv3的详细过程 (亲测成功, 20180529更新)
    Caffe初学者第一部:Ubuntu14.04上安装caffe(CPU)+Python的详细过程 (亲测成功, 20180524更新)
  • 原文地址:https://www.cnblogs.com/yansc/p/1402836.html
Copyright © 2011-2022 走看看