0
我我的WPF MVVM應用我想上傳到database.The碼圖像操作正常,並且將圖像保存到數據庫作爲image.I需要實施調整而upload.I圖像意思是當點擊上傳圖片將動態調整,並保存到數據庫 這裏是我的代碼調整圖片大小,而文件上傳
public void Upload(object obj)
{
try
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".png";
dlg.Filter = "Image files (*.png;*.jpg)|*.png;*.jpg";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string filename = dlg.FileName;
UploadText = filename;
FileStream FS = new FileStream(filename, FileMode.Open, FileAccess.Read);
byte[] img = new byte[FS.Length];
FS.Read(img, 0, Convert.ToInt32(FS.Length));
UploadLogo = img;
Stream reader = File.OpenRead(filename);
System.Drawing.Image photo = System.Drawing.Image.FromStream((Stream)reader);
MemoryStream finalStream = new MemoryStream();
photo.Save(finalStream, ImageFormat.Png);
// translate to image source
PngBitmapDecoder decoder = new PngBitmapDecoder(finalStream, BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.Default);
ClientLogo = decoder.Frames[0]; ;
}
}
catch (Exception ex)
{
throw ex;
}
}
請幫
在此先感謝
[相關(http://stackoverflow.com/q/15779564/1997232) – Sinatr 2014-11-05 14:46:52