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);

            }

  • 相关阅读:
    卸载了PL/SQL Developer,说一下与Toad for Oracle的对照
    列举游戏开发过程中的一些不良现象
    vue23:vue-loader
    vue22 路由
    vue21 slot占位
    vue20 父子组件数据交互
    vue19 组建 Vue.extend component、组件模版、动态组件
    vue18 动画
    vue17 $watch 监听数据变化
    vue16 自定义键盘属性
  • 原文地址:https://www.cnblogs.com/yansc/p/1402836.html
Copyright © 2011-2022 走看看