现在的位置: 首页 > 综合 > 正文

image与byte数组的转换[引用]

2012年12月29日 ⁄ 综合 ⁄ 共 602字 ⁄ 字号 评论关闭

 

image to byte[]

  MemoryStream ms=new MemoryStream();
   byte[] imagedata=null;
   pictureBox1.Image.Save(ms,System.Drawing.Imaging.ImageFormat.Gif );
   imagedata=ms.GetBuffer ();

byte[] to image

System.Drawing.Image img;
        MemoryStream ms=new MemoryStream();
        ms = new System.IO.MemoryStream((byte[])Content );
        img = System.Drawing.Image.FromStream(ms);
        if(img.Width>Convert.ToInt32( _width))
        {
         _width=500;
         _height=(img.Height*Convert.ToInt32(_width))/img.Width;
        }
        else
        {
         _width=img.Width;
         _height=img.Height;
        }
        img.Dispose();

抱歉!评论已关闭.