开发者

i converted a bitmap picture to byte arraye and string .how can i convert this string to that bitmap picture again?

 public byte[] PictureByt开发者_如何学JAVAeArray
        {
            get
            {
                //get a TypeConverter object for converting Bitmap to bytes
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(Bitmap));
                byte[] byteArr = (byte[])converter.ConvertTo(source, typeof(byte[]));
                return byteArr;
            }
            set
            {
                source = new Bitmap(new MemoryStream(value));
            }
        }


  System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            s = enc.GetString(bytes);


I usually use these two methods for converting an image to a byte array, and back again, for example when transferring an image to a web service, and retrieving it back again:

public static byte[] ImageToByteArray(System.Drawing.Image imageIn) {
  MemoryStream ms = new MemoryStream();
  Bitmap image = new Bitmap(imageIn);
  image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  return ms.ToArray();
}

public static Image ByteArrayToImage(byte[] byteArray) {
  MemoryStream ms = new MemoryStream(byteArray);
  Image returnImage = Image.FromStream(ms);
  return returnImage;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜