public Photo(string path) { _pathOriginal = path; using (var image = System.Drawing.Image.FromFile(_pathOriginal)) { using (var newImageSmall = ImageWorker.ConverImageToBitmap(image, 130, 130)) { if (newImageSmall != null) { using (MemoryStream ms = new MemoryStream()) { newImageSmall.Save(ms, ImageFormat.Bmp); _image = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } using (var newImageOrigin = ImageWorker.ConverImageToBitmap(image, image.Width, image.Height)) { if (newImageOrigin != null) { using (MemoryStream ms = new MemoryStream()) { newImageOrigin.Save(ms, ImageFormat.Bmp); _imageOrigin = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } } }
public Photo(ProductImageViewModel path) // конструктор получения изображений из базы { _path = path.GetImageSmall; _pathOriginal = path.GetImageOriginal; using (var image = System.Drawing.Image.FromFile(_pathOriginal)) { using (var newImageSmall = ImageWorker.ConverImageToBitmap(image, 130, 130)) { if (newImageSmall != null) { using (MemoryStream ms = new MemoryStream()) { newImageSmall.Save(ms, ImageFormat.Bmp); _image = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } using (var newImageOrigin = ImageWorker.ConverImageToBitmap(image, image.Width, image.Height)) { if (newImageOrigin != null) { using (MemoryStream ms = new MemoryStream()) { newImageOrigin.Save(ms, ImageFormat.Bmp); _imageOrigin = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } } }
public Photo(string path) { //if(!(Directory.Exists(Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImagePath"].ToString()))) // Directory.CreateDirectory(Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImagePath"].ToString()); // _pathOriginal = path; //_path = "L:\\Temp\\" + Guid.NewGuid().ToString() + ".jpg"; //_path = Environment.CurrentDirectory + ConfigurationManager.AppSettings["ImagePath"].ToString() + Guid.NewGuid().ToString() + ".jpg"; using (var image = System.Drawing.Image.FromFile(_pathOriginal)) { using (var newImageSmall = ImageWorker.ConverImageToBitmap(image, 130, 130)) { #region oldcode //if (newImageSmall != null) //{ // //newImageSmall.Save(_path, System.Drawing.Imaging.ImageFormat.Jpeg); // //newImageSmall.Dispose(); // using (MemoryStream ms = new MemoryStream()) // { // //newImageSmall.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // //JpegBitmapEncoder encoder = new JpegBitmapEncoder(); // TiffBitmapEncoder encoder = new TiffBitmapEncoder(); // //encoder.Frames.Add(BitmapFrame.Create(new Uri(path))); // encoder.Frames.Add(BitmapFrame.Create(this.Convert(newImageSmall))); // encoder.Save(ms); // _image = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); // //_image = System.Drawing.Image.FromStream(ms); // } // //_image = BitmapFrame.Create(new Uri(_path)); //} #endregion if (newImageSmall != null) { using (MemoryStream ms = new MemoryStream()) { newImageSmall.Save(ms, ImageFormat.Bmp); _image = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } using (var newImageOrigin = ImageWorker.ConverImageToBitmap(image, image.Width, image.Height)) { if (newImageOrigin != null) { using (MemoryStream ms = new MemoryStream()) { newImageOrigin.Save(ms, ImageFormat.Bmp); _imageOrigin = BitmapFrame.Create(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); } } } //_source = new Uri(path); } }