MyPictures - Blank pics when viewing shares [SVN 11182006] (1 Viewer)

htpcNoob

Portal Pro
January 23, 2005
52
0
This is my first (bug?) post so not sure if this is where it goes. This is the temporary fix I came up with - which I know you guys can implement a better, more generic code for.

When viewing pictures stored in windows shares I get blank pics. Mediaportal.log reported an exception in picture.load stating that it was an access denial error with the picture. Even after allowing full rights with the share the same error occured. After doing some digging the problem seemed to boil down to Util\Pictures.cs Load(string strPic,....) function. The problem was with the code

Code:
using (FileStream stream = new FileStream(strPic, FileMode.Open))
line. It kept throwing the exception.

So I decided to change the code to:
Code:
using (FileStream stream = new FileStream(strPic, FileMode.Open, FileAccess.Read))

Still the same problem occured.

Turns out the problem has something to do with the stream outlined in http://www.pixvillage.com/blogs/devblog/archive/2005/03/09/154.aspx

I created a new class from the code referenced in the above link and called it StreamedImage.cs and placed it in the util directory. Here is the code:

Code:
using System;
using System.Drawing;
using System.IO;

namespace MediaPortal.Util
{
    public class StreamedImage : IDisposable
    {
        private Image image;
        private Stream stream;

        public StreamedImage(Stream stream, bool useEmbeddedColorManagement, bool validateImageData)
        {
            this.stream = stream;
            this.image = System.Drawing.Image.FromStream(stream, useEmbeddedColorManagement, validateImageData);
        }

        public Image Image
        {
            get { return image; }
        }


        public Stream Stream
        {
            get { return stream; }
        }

        public void Dispose()
        {
            if (image != null)
            {
                image.Dispose();
                image = null;
            }

            if (stream != null)
            {
                stream.Close();
                stream = null;
            }
        }
    }
}

In Picture.cs load function, I changed the line of code
Code:
using (FileStream stream = new FileStream(strPic, FileMode.Open))
to
Code:
StreamedImage sim = new StreamedImage(new FileStream(strPic, FileMode.Open, FileAccess.Read), true, false);

below that there was a variable theImage referencing the image from the original stream:
Code:
theImage = Image.FromStream(stream, true, false);
.

This was changed to:
Code:
theImage = sim.Image;

I recompiled MP and put that code into play. Fixed my problem. I'm not sure if this was the exact right approach but it worked for me.
 

Users who are viewing this thread

Top Bottom