home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Fix for thumbnail problem in MyPictures
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="gloomyandy" data-source="post: 90602" data-attributes="member: 24855"><p>Firstly sorry if this is not the correct way to submit a potential bug fix! My first attempt so be gentle!</p><p></p><p>Ok I finally got fed up enough with the problem I reported below:</p><p><a href="https://forum.team-mediaportal.com/showthread.php?t=12077" target="_blank">https://forum.team-mediaportal.com/showthread.php?t=12077</a></p><p></p><p>To try and do something about it. I grabbed a copy of VC# Express and the latest svn source and had a look. The code in question is in file GUIPictures.cs and is in methods CreateFolderThumb and LoadPicture.I found that on creating the thimbnails the DrawImage function was throwing an exception on the face of it there was no obvious reason as to why, the original image had been loaded ok and the background image was also ok. </p><p></p><p>After a bit of digging I came across this web page:</p><p><a href="http://www.pixvillage.com/blogs/devblog/archive/2005/03/09/154.aspx" target="_blank">http://www.pixvillage.com/blogs/devblog/archive/2005/03/09/154.aspx</a></p><p>Which also has a pointer to a MS knowledge base article. </p><p></p><p>Basically what these say is that when you load an image from a file or a stream the actual reading of the image may be delayed until the image is used. Destroying the file or the stream before the image may result in "bad things happening". Now the code i(that loads the picture) is creating a stream (and then creating an image from this stream) using a "using block" so the stream will be disposed of when the block exits. The bad news is the function then goes on to return the image created from the stream to the calling function so the lifetime of the stream is < the lifetime of the image.</p><p></p><p>To fix this I re-factored the code a little so that the drawing of the image takes place within a new function AddPicture which replaces the old LoadPicture. The code is shown below (I've attached the complete file to this post as a text file):</p><p></p><p> [CODE] </p><p> void AddPicture(Graphics g, string strFileName, int x, int y, int w, int h)</p><p> {</p><p> // Add a thumbnail of the specified picture file to the image referenced by g, draw it at the</p><p> // given location and size.</p><p> Image img = null;</p><p> using (PictureDatabase dbs = new PictureDatabase())</p><p> {</p><p> int iRotate = dbs.GetRotation(strFileName);</p><p></p><p> using (FileStream stream = new FileStream(strFileName, FileMode.Open))</p><p> {</p><p> img = Image.FromStream(stream, true, false);</p><p></p><p> if (img != null)</p><p> {</p><p> if (iRotate > 0)</p><p> {</p><p> RotateFlipType flipType;</p><p> switch (iRotate)</p><p> {</p><p> case 1:</p><p> flipType = RotateFlipType.Rotate90FlipNone;</p><p> img.RotateFlip(flipType);</p><p> break;</p><p> case 2:</p><p> flipType = RotateFlipType.Rotate180FlipNone;</p><p> img.RotateFlip(flipType);</p><p> break;</p><p> case 3:</p><p> flipType = RotateFlipType.Rotate270FlipNone;</p><p> img.RotateFlip(flipType);</p><p> break;</p><p> default:</p><p> flipType = RotateFlipType.RotateNoneFlipNone;</p><p> break;</p><p> }</p><p> }</p><p> g.DrawImage(img, x, y, w, h);</p><p> }</p><p> }</p><p> }</p><p> }</p><p></p><p>[/CODE]</p><p></p><p>This is then called as shown:</p><p></p><p>[CODE]</p><p> using (Bitmap bmp = new Bitmap(width, height))</p><p> {</p><p> using (Graphics g = Graphics.FromImage(bmp))</p><p> {</p><p> g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;</p><p> g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;</p><p> g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;</p><p></p><p> g.DrawImage(imgFolder, 0, 0, width, height);</p><p> int x, y, w, h;</p><p> x = 0; y = 0; w = thumbnailWidth; h = thumbnailHeight;</p><p> //Load first of 4 images for the folder thumb.</p><p> //Avoid crashes caused by damaged image files:</p><p> try</p><p> {</p><p> AddPicture(g, (string)pictureList[0], x + 10, y + 10, w, h);</p><p> }</p><p> catch (Exception)</p><p> {</p><p> Log.Info("Damaged picture file found: {0}. Try to repair or delete this file please!", (string)pictureList[0]);</p><p> }</p><p>[/CODE]</p><p></p><p>With the above changes I no longer get exceptions when the image is drawn to the thumbnail and thumbnails are created for all of my picture folders with no errors. It is worth noting that if the old LoadPicture function needed to rotate the picture then this would have resulted in the image being initialized from the stream while the stream still existed and so no exception would have been thrown. This fits perfectly with what I was seeing, some pictures used for thumbnails seemed to be ok others did not. On closer inspection the files that worked required rotation, the ones that failed did not.</p><p></p><p>Hope this makes sense....</p><p></p><p>Andy</p><p></p><p>Added to SF as patch</p><p>[ 1597327 ] Blank thumbnail for directories in MyPictures</p><p><a href="https://sourceforge.net/tracker/index.php?func=detail&aid=1597327&group_id=107397&atid=647927" target="_blank">https://sourceforge.net/tracker/index.php?func=detail&aid=1597327&group_id=107397&atid=647927</a></p></blockquote><p></p>
[QUOTE="gloomyandy, post: 90602, member: 24855"] Firstly sorry if this is not the correct way to submit a potential bug fix! My first attempt so be gentle! Ok I finally got fed up enough with the problem I reported below: [url]https://forum.team-mediaportal.com/showthread.php?t=12077[/url] To try and do something about it. I grabbed a copy of VC# Express and the latest svn source and had a look. The code in question is in file GUIPictures.cs and is in methods CreateFolderThumb and LoadPicture.I found that on creating the thimbnails the DrawImage function was throwing an exception on the face of it there was no obvious reason as to why, the original image had been loaded ok and the background image was also ok. After a bit of digging I came across this web page: [url]http://www.pixvillage.com/blogs/devblog/archive/2005/03/09/154.aspx[/url] Which also has a pointer to a MS knowledge base article. Basically what these say is that when you load an image from a file or a stream the actual reading of the image may be delayed until the image is used. Destroying the file or the stream before the image may result in "bad things happening". Now the code i(that loads the picture) is creating a stream (and then creating an image from this stream) using a "using block" so the stream will be disposed of when the block exits. The bad news is the function then goes on to return the image created from the stream to the calling function so the lifetime of the stream is < the lifetime of the image. To fix this I re-factored the code a little so that the drawing of the image takes place within a new function AddPicture which replaces the old LoadPicture. The code is shown below (I've attached the complete file to this post as a text file): [CODE] void AddPicture(Graphics g, string strFileName, int x, int y, int w, int h) { // Add a thumbnail of the specified picture file to the image referenced by g, draw it at the // given location and size. Image img = null; using (PictureDatabase dbs = new PictureDatabase()) { int iRotate = dbs.GetRotation(strFileName); using (FileStream stream = new FileStream(strFileName, FileMode.Open)) { img = Image.FromStream(stream, true, false); if (img != null) { if (iRotate > 0) { RotateFlipType flipType; switch (iRotate) { case 1: flipType = RotateFlipType.Rotate90FlipNone; img.RotateFlip(flipType); break; case 2: flipType = RotateFlipType.Rotate180FlipNone; img.RotateFlip(flipType); break; case 3: flipType = RotateFlipType.Rotate270FlipNone; img.RotateFlip(flipType); break; default: flipType = RotateFlipType.RotateNoneFlipNone; break; } } g.DrawImage(img, x, y, w, h); } } } } [/CODE] This is then called as shown: [CODE] using (Bitmap bmp = new Bitmap(width, height)) { using (Graphics g = Graphics.FromImage(bmp)) { g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.DrawImage(imgFolder, 0, 0, width, height); int x, y, w, h; x = 0; y = 0; w = thumbnailWidth; h = thumbnailHeight; //Load first of 4 images for the folder thumb. //Avoid crashes caused by damaged image files: try { AddPicture(g, (string)pictureList[0], x + 10, y + 10, w, h); } catch (Exception) { Log.Info("Damaged picture file found: {0}. Try to repair or delete this file please!", (string)pictureList[0]); } [/CODE] With the above changes I no longer get exceptions when the image is drawn to the thumbnail and thumbnails are created for all of my picture folders with no errors. It is worth noting that if the old LoadPicture function needed to rotate the picture then this would have resulted in the image being initialized from the stream while the stream still existed and so no exception would have been thrown. This fits perfectly with what I was seeing, some pictures used for thumbnails seemed to be ok others did not. On closer inspection the files that worked required rotation, the ones that failed did not. Hope this makes sense.... Andy Added to SF as patch [ 1597327 ] Blank thumbnail for directories in MyPictures [url]https://sourceforge.net/tracker/index.php?func=detail&aid=1597327&group_id=107397&atid=647927[/url] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Fix for thumbnail problem in MyPictures
Contact us
RSS
Top
Bottom