I my wpf mvvm application I am trying to upload an image to the database.The code is working fine and the image save to the db as image.I need to implement resize the image while upload.I mean When click upload the image will resize dynamically and save to db Here is my code
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;
}
}
Please help
Thanks in advance