111,098
社区成员




private void BindingImageSource(byte[] _imgByte)//显示image
{
/*6. 将二进制转化为Imagesource,在Image上显示*/
ImageSource imgSource = ChangeBitmapToBitmapSource(SetByteToBitmap(_imgByte));
image1.Source = imgSource;
}
public static BitmapSource ChangeBitmapToBitmapSource(Draw.Bitmap bmp)
{
BitmapSource returnSource = null;
try
{
returnSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
catch
{
returnSource = null;
}
return returnSource;
}
public Draw.Bitmap SetByteToBitmap(byte[] mybyte)
{
MemoryStream stream = new MemoryStream(mybyte);
return new Draw.Bitmap(stream);
}
bt = (byte[])reader[i];
//str = Encoding.ASCII.GetString(bt);
//str = str.Substring(str.IndexOf("BM"), str.Length - str.IndexOf("BM"));
//bt = Encoding.ASCII.GetBytes(str);
MemoryStream buf = new MemoryStream(bt);
Bitmap mp = (Bitmap)Bitmap.FromStream(buf, true, true);
//mp = RePic(mp, mp.Width, mp.Height);
//mp.Save(@"C:\Data\a.jpg", System.Drawing.Imaging.ImageFormat.jpeg);
this.pictureBox1.Image = mp;