将picturebox.resourse转换为byte [] Array,将其发送到数据库WPF [英] convert picturebox.resourse to byte[] Array to send it to database WPF
问题描述
我需要转换图像( picturebox.resourse )中的帮助 中的字节数组( byte [] ) WPF
id使用此代码:但无法解析第二行
保存(ms,System.Drawing.Imaging.ImageFormat.Jpeg );
我的代码是:
MemoryStream ms = new MemoryStream();
picturebox.Resources。 保存 (ms,System.Drawing.Imaging.ImageFormat.Jpeg);
byte [] pic_arr = new byte [ms.Length];
ms.Position = 0;
ms.Read(pic_arr,0,pic_arr.Length);
如果你能帮助我,我将不胜感激。
i need help in converting image(picturebox.resourse) to byte array (byte[]) in WPF
id used this code : but it cannot resolve second line
"Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);"
my code is :
MemoryStream ms = new MemoryStream();
picturebox.Resources.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic_arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(pic_arr, 0, pic_arr.Length);
Please If You can help me I would be grateful.
推荐答案
Bitmap bitmapImage = picturebox.Resourses;
byte[] data;
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmapImage));
using(MemoryStream ms = new MemoryStream())
{
encoder.Save(ms);
data = ms.ToArray();
}
private void GetImage(byte[] pic)
{
byte[] data = (byte[])pic;
MemoryStream strm = new MemoryStream();
strm.Write(data, 0, data.Length);
strm.Position = 0;
System.Drawing.Image img = System.Drawing.Image.FromStream(strm);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
bi.StreamSource = ms;
bi.EndInit();
pbStuPic.Source = bi;
}
we caled like this
var bits = getJPGFromImageControl(pbStuPic.Source as BitmapImage);
它无法在wpf .net 4.5中解析(bitmapImage)此解决方案
i am using using vsoz>
问题是:
i有主窗体的图片框,我需要把它放在byte []中发送它到数据库
i访问图片框中的图片像这样
picturebox.Resourses = ....
it can not resolve (bitmapImage) this solution in wpf .net 4.5
i am using vs2012
the problem is :
i have picture box in main form and i need to put it in byte[] to send it to database
i access to the picture in picturebox like this
picturebox.Resourses=....
这篇关于将picturebox.resourse转换为byte [] Array,将其发送到数据库WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!