From 85d774a27351e61f9ef88197f8dd2851acf1764d Mon Sep 17 00:00:00 2001 From: Kathy Date: Fri, 21 Oct 2016 14:05:49 +0000 Subject: [PATCH] =?UTF-8?q?B2016-235:=20files=20with=20extension=20of=20?= =?UTF-8?q?=E2=80=98.tiff=E2=80=99=20failed=20in=20Embedded=20image=20supp?= =?UTF-8?q?ort.=20B2016-234:=20Inserting=20image=20=E2=80=98after=E2=80=99?= =?UTF-8?q?=20with=20delete=20caused=20crash.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PROMS/Volian.Controls.Library/ImageItem.cs | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/PROMS/Volian.Controls.Library/ImageItem.cs b/PROMS/Volian.Controls.Library/ImageItem.cs index 83a7de88..e6c2cadc 100644 --- a/PROMS/Volian.Controls.Library/ImageItem.cs +++ b/PROMS/Volian.Controls.Library/ImageItem.cs @@ -788,11 +788,12 @@ namespace Volian.Controls.Library using (Item _MyItem = MyItemInfo.Get()) { byte[] imgToByte = imageToByteArray(MyPictureBox.Image, FileName); + if (imgToByte == null) return; int origLen = imgToByte.Length; bool compressed = false; // if file is a tif or bmp see if compressing it saves space and if so, save the // compressed data with a flag in config, the size needed to decompress, to show it is compressed. - if (FileName.ToUpper().EndsWith(".TIF") || FileName.ToUpper().EndsWith(".BMP")) + if (FileName.ToUpper().EndsWith(".TIFF") || FileName.ToUpper().EndsWith(".TIF") || FileName.ToUpper().EndsWith(".BMP")) { byte[] cmp = ROImageInfo.Compress(imgToByte); if (origLen > cmp.Length) @@ -874,6 +875,7 @@ namespace Volian.Controls.Library ifmt = System.Drawing.Imaging.ImageFormat.Jpeg; break; case ("TIF"): + case ("TIFF"): ifmt = System.Drawing.Imaging.ImageFormat.Tiff; break; case ("WMF"): @@ -930,27 +932,43 @@ namespace Volian.Controls.Library else img = null; } - if (img==null) + if (img == null) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Image files (*.jpg;*.tif;*.bmp;*.png)|*.jpg;*.tif;*.bmp;*.png|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 0; openFileDialog1.RestoreDirectory = true; - if (openFileDialog1.ShowDialog() == DialogResult.OK) + DialogResult dr = openFileDialog1.ShowDialog(); + if (dr == DialogResult.OK) { // check that it is an image - img = System.Drawing.Image.FromFile(openFileDialog1.FileName); + try + { + img = System.Drawing.Image.FromFile(openFileDialog1.FileName); + } + catch (Exception ex) + { + img = null; + } if (img != null) filename = openFileDialog1.FileName; } - if (filename == null) return; // user must have existed out. How to handle?? + if (filename == null) + { + if (dr != DialogResult.Cancel) + { + string msg = string.Format("Could not display image {0}.", openFileDialog1.FileName); + MessageBox.Show(msg); + } + return; // user must have exited out or entered a bad filename. + } } byte[] imgToByte = imageToByteArray(img, filename); int origLen = imgToByte.Length; bool compressed = false; // if file is a tif or bmp see if compressing it saves space and if so, save the // compressed data with a flag in config, the size needed to decompress, to show it is compressed. - if (filename.ToUpper().EndsWith(".TIF") || filename.ToUpper().EndsWith(".BMP")) + if (filename.ToUpper().EndsWith(".TIFF") || filename.ToUpper().EndsWith(".TIF") || filename.ToUpper().EndsWith(".BMP")) { byte[] cmp = ROImageInfo.Compress(imgToByte); if (origLen > cmp.Length)