Example #1
0
        private void FetchImage()
        {
            bool sizeIsSet = Size != null && Size.Height > 0 && Size.Width > 0;

            localPath = localImage.GetLocalImagePath();
            if (sizeIsSet)
            {
                localPath = localImage.GetLocalImagePath(Size.Width, Size.Height);
            }

            if (localImage.Corrupt)
            {
                Logger.ReportWarning("Image " + localPath + " is Corrupt.");
                doneProcessing = true;
                IsLoaded       = true;
                Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ =>
                {
                    if (afterLoad != null)
                    {
                        afterLoad();
                    }
                });
                return;
            }



            Image newImage = null;


            Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ =>
            {
                if (newImage == null)
                {
                    //Logger.ReportVerbose("Loading image : " + localPath);
                    string imageRef = "file://" + localPath;
                    newImage        = new Image(imageRef);
                }

                lock (this) {
                    image = newImage;
                    if (!sizeIsSet)
                    {
                        size = new Size(localImage.Width, localImage.Height);
                    }
                    doneProcessing = true;
                }

                IsLoaded = true;

                if (afterLoad != null)
                {
                    afterLoad();
                }
            });
        }
        private void FetchImage()
        {
            bool sizeIsSet = Size != null && Size.Height > 0 && Size.Width > 0;

            localPath = localImage.GetLocalImagePath();
            if (sizeIsSet)
            {
                localPath = localImage.GetLocalImagePath(Size.Width, Size.Height);
            }

            if (localImage.Corrupt)
            {
                Logger.ReportWarning("Image " + localPath + " is Corrupt.");
                doneProcessing = true;
                IsLoaded       = true;
                Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ =>
                {
                    if (afterLoad != null)
                    {
                        afterLoad();
                    }
                });
                return;
            }



            Image newImage = null;

            if (Kernel.Instance.ConfigData.CacheAllImagesInMemory)
            {
                //defunct code..
                //if (Kernel.Instance.ConfigData.UseSQLImageCache)
                //{
                //    Logger.ReportVerbose("Loading image (from sql): " + localPath);
                //    var imageStream = ImageCache.Instance.GetImageStream(localImage.Id, localImage.Width);
                //    //System.Drawing.Image test = System.Drawing.Image.FromStream(imageStream);
                //    //test.Save("c:\\users\\eric\\my documents\\imagetest\\" + localImage.Id + localImage.Width + ".png");
                //    //test.Dispose();
                //    newImage = (Image)ImageFromStream.Invoke(null, new object[] { null, imageStream });
                //}
                //else
                {
                    Logger.ReportVerbose("Loading image (cacheall true) : " + localPath);
                    byte[] bytes;
                    lock (ProtectedFileStream.GetLock(localPath))
                    {
                        bytes = File.ReadAllBytes(localPath);
                    }

                    MemoryStream imageStream = new MemoryStream(bytes);
                    imageStream.Position = 0;
                    newImage             = (Image)ImageFromStream.Invoke(null, new object[] { null, imageStream });
                }
            }


            Microsoft.MediaCenter.UI.Application.DeferredInvoke(_ =>
            {
                if (newImage == null)
                {
                    //Logger.ReportVerbose("Loading image : " + localPath);
                    string imageRef = "file://" + localPath;
                    newImage        = new Image(imageRef);
                }

                lock (this) {
                    image = newImage;
                    if (!sizeIsSet)
                    {
                        size = new Size(localImage.Width, localImage.Height);
                    }
                    doneProcessing = true;
                }

                IsLoaded = true;

                if (afterLoad != null)
                {
                    afterLoad();
                }
            });
        }