大赵传奇

援引事类,扬搉古今,举要删芜,言辩而理切--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

        }

posted on 2009-03-04 11:30  赵长青  阅读(872)  评论(2编辑  收藏  举报