private void showImageFromPath(string fileName) { try { pictureBox2.Image = null; if (!System.IO.File.Exists(fileName)) { return; } ImageIO io = new ImageIO(); Bitmap newImage = io.Open(fileName); double scaleX = (double)pictureBox2.Width / (double)newImage.Width; double scaleY = (double)pictureBox2.Height / (double)newImage.Height; double Scale = Math.Min(scaleX, scaleY); int w = (int)(newImage.Width * Scale); int h = (int)(newImage.Height * Scale); pictureBox2.Image = newImage.GetThumbnailImage(w, h, new System.Drawing.Image.GetThumbnailImageAbort(GetThumbnailImageAbort), IntPtr.Zero); } catch (Exception ex) { MessageBox.Show("Image is not displayed because:" + Environment.NewLine + ex.Message); } }
private void DisplayImage(string fileName) { try { PictureBox1.Image = null; if (!System.IO.File.Exists(fileName)) return; ImageIO io = new ImageIO(); Bitmap newImage = io.Open(fileName); double scaleX = (double) PictureBox1.Width / (double) newImage.Width; double scaleY = (double) PictureBox1.Height / (double) newImage.Height; double Scale = Math.Min(scaleX, scaleY); int w = (int) (newImage.Width * Scale); int h = (int) (newImage.Height * Scale); PictureBox1.Image = newImage.GetThumbnailImage(w, h, new System.Drawing.Image.GetThumbnailImageAbort(GetThumbnailImageAbort), IntPtr.Zero); } catch (Exception ex) { MessageBox.Show("Image is not displayed because:" + Environment.NewLine + ex.Message); } }