public static ImageSource resizeImage(ImageSource input_image, int pixel_height, int pixel_width, ResizeAffectMode resize_mode = ResizeAffectMode.pixelSize, double dpi = 0) { try { bool fit_width = _should_fit_with(input_image.Height, input_image.Width); BitmapSource base_source = input_image as BitmapSource; //Bitmap source is the base of all imagesources. So, we can convert them to bitmapsource without issue. if (base_source == null) { return(null); } switch (resize_mode) { case ResizeAffectMode.pixelSize: return(_resizeImage_pixelOnly(base_source, pixel_height, pixel_width, fit_width)); case ResizeAffectMode.pixelSize_imageSize: return(_resizeImage_pixelImage(base_source, pixel_height, pixel_width, fit_width, dpi)); case ResizeAffectMode.pixelSize_dpi: return(_resizeImage_pixelDpi(base_source, pixel_height, pixel_width, fit_width, dpi)); } return(null); } catch (Exception ex) { throw ex; } }
public static ImageSource resizeImage(byte[] image_byte_array, int pixel_height, int pixel_width, ResizeAffectMode resize_mode = ResizeAffectMode.pixelSize, double dpi = 0) { try { BitmapImage result_image = new BitmapImage(); using (MemoryStream mstream = new MemoryStream(image_byte_array)) { result_image.BeginInit(); result_image.StreamSource = mstream; result_image.EndInit(); } return(resizeImage((ImageSource)result_image, pixel_height, pixel_width, resize_mode, dpi)); } catch (Exception ex) { throw ex; } }
public static ImageSource resizeImage(Uri path_URI, int pixel_height, int pixel_width, ResizeAffectMode resize_mode = ResizeAffectMode.pixelSize, double dpi = 0) { try { BitmapImage image = new BitmapImage(path_URI); return(resizeImage(image, pixel_height, pixel_width, resize_mode, dpi)); } catch (Exception ex) { throw ex; } }
public static ImageSource resizeImage(Image image, int pixel_height, int pixel_width, ResizeAffectMode resize_mode = ResizeAffectMode.pixelSize, double dpi = 0) { try { bool fit_width = _should_fit_with(Convert.ToDouble(image.Height), Convert.ToDouble(image.Width)); return(resizeImage(imageToByte(image), pixel_height, pixel_width, resize_mode, dpi)); } catch (Exception ex) { throw ex; } }
public static ImageSource resizeImage(string path, int pixel_height, int pixel_width, ResizeAffectMode resize_mode = ResizeAffectMode.pixelSize, double dpi = 0) { try { Uri image_uri = new Uri(path, UriKind.RelativeOrAbsolute); return(resizeImage(image_uri, pixel_height, pixel_width, resize_mode, dpi)); } catch (Exception ex) { throw ex; } }