private Stream GetResizedImage(Stream originalStream, ImageSize size, string fileName)
        {
            BitmapFrame frame = ImageHelper.ReadBitmapFrame(originalStream);
            BitmapFrame resizedFrame = frame.ResizeImage(size.Width, size.Height);

            if (Settings.UseLocalCache)
            {
                string name = ResolveFileName(fileName, size.ToString());
                resizedFrame.SaveToFile(name);
                return OpenImageStream(name);
            }
            return resizedFrame.GetStream();
        }
        private Stream GetResultStream(Uri uri, ImageSize imageSize)
        {
            if (Settings.UseLocalCache)
            {
                string requestFileName = GetDownloadPath(uri);
                string cachedFileName = ResolveFileName(requestFileName, imageSize.ToString());

                // looking for cached file on disk
                if (File.Exists(cachedFileName))
                {
                    return OpenImageStream(cachedFileName);
                }

                // looking for original file on disk
                string original = ResolveFileName(requestFileName, ImageSize.OriginalImageSize);

                if (File.Exists(original))
                {
                    return GetResizedImage(OpenImageStream(original), imageSize, requestFileName);
                }
            }
            return GetImageStream(uri, imageSize);
        }
        private Stream GetImageStream(Uri uri, ImageSize imageSize)
        {
            try
            {
                var request = (HttpWebRequest)HttpWebRequest.Create(uri);
                request.UserAgent = Settings.UserAgent;

                using (var response = request.GetResponse())
                {
                    var imageStream = new MemoryStream();
                    using (var responseStream = response.GetResponseStream())
                    {
                        responseStream.CopyTo(imageStream);
                        imageStream.Position = 0;
                    }

                    if (Settings.UseLocalCache)
                    {
                        SaveOriginalFileToDisk(imageStream, uri);
                    }
                    return (imageSize.Name == ImageSize.OriginalImageSize) ?
                        imageStream :
                        GetResizedImage(imageStream, imageSize, GetDownloadPath(uri));
                }
            }
            catch (Exception exc)
            {
                Trace.TraceError(exc.ToString());
                return GetErrorStream();
            }
        }