예제 #1
0
 /// <summary>
 /// Downloads the image from the server and saves it to a local file.
 /// </summary>
 /// <param name="obj">The image data. Instance of ImageDownloadInfo used in cross thread data sharing.</param>
 private void DownloadImage(Object obj)
 {
     try
     {
         ImageDownloadInfo idi          = (ImageDownloadInfo)obj;
         String            targetFolder = idi.DownloadFolder;
         //remove parameters from URI(.net 'Path' does not delete or warn about them)
         String    URI       = idi.URI.Split('?')[0];
         WebClient webClient = new WebClient();
         if (!Directory.Exists(targetFolder))
         {
             Directory.CreateDirectory(targetFolder);
         }
         String     path          = targetFolder + "\\" + Path.GetFileName(URI);
         FileInfo   fileInfo      = new FileInfo(path);
         byte[]     binaryContent = webClient.DownloadData(URI);
         FileStream fileStream    = fileInfo.Create();
         fileStream.Write(binaryContent, 0, binaryContent.Length);
         fileStream.Close();
         //Set the image element properties in the converters imageList.
         idi.ImageInfo.filePath         = fileInfo.FullName;
         idi.ImageInfo.imgLocalSrc      = "file:///" + fileInfo.FullName.Replace("\\", "/");
         idi.ImageInfo.fileURI          = URI;
         idi.ImageInfo.fileSize         = fileInfo.Length;
         idi.ImageInfo.fileCreationDate = fileInfo.CreationTime;
     }
     catch (InvalidCastException) { }
     catch (WebException) { };
 }
예제 #2
0
        private void AddCover(BaseItem item, StubType?stubType, XmlWriter writer)
        {
            ImageDownloadInfo imageInfo = GetImageInfo(item);

            if (imageInfo == null)
            {
                return;
            }

            // TODO: Remove these default values
            var albumArtUrlInfo = GetImageUrl(
                imageInfo,
                _profile.MaxAlbumArtWidth ?? 10000,
                _profile.MaxAlbumArtHeight ?? 10000,
                "jpg");

            writer.WriteStartElement("upnp", "albumArtURI", NsUpnp);
            if (!string.IsNullOrEmpty(_profile.AlbumArtPn))
            {
                writer.WriteAttributeString("dlna", "profileID", NsDlna, _profile.AlbumArtPn);
            }

            writer.WriteString(albumArtUrlInfo.url);
            writer.WriteFullEndElement();

            // TODO: Remove these default values
            var iconUrlInfo = GetImageUrl(
                imageInfo,
                _profile.MaxIconWidth ?? 48,
                _profile.MaxIconHeight ?? 48,
                "jpg");

            writer.WriteElementString("upnp", "icon", NsUpnp, iconUrlInfo.url);

            if (!_profile.EnableAlbumArtInDidl)
            {
                if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    if (!stubType.HasValue)
                    {
                        return;
                    }
                }
            }

            if (!_profile.EnableSingleAlbumArtLimit || string.Equals(item.MediaType, MediaType.Photo, StringComparison.OrdinalIgnoreCase))
            {
                AddImageResElement(item, writer, 4096, 4096, "jpg", "JPEG_LRG");
                AddImageResElement(item, writer, 1024, 768, "jpg", "JPEG_MED");
                AddImageResElement(item, writer, 640, 480, "jpg", "JPEG_SM");
                AddImageResElement(item, writer, 4096, 4096, "png", "PNG_LRG");
                AddImageResElement(item, writer, 160, 160, "png", "PNG_TN");
            }

            AddImageResElement(item, writer, 160, 160, "jpg", "JPEG_TN");
        }
예제 #3
0
        public static void AssignImageAsync(ImageView image, string url, Activity context)
        {
            var info = new ImageDownloadInfo
            {
                ImageView = image,
                ImageUrl = url,
                Context = context,
            };

            ThreadPool.QueueUserWorkItem(DownloadImage, info);
        }
예제 #4
0
        public static void AssignImageAsync(ImageView image, string url, Activity context)
        {
            var info = new ImageDownloadInfo
            {
                ImageView = image,
                ImageUrl  = url,
                Context   = context
            };

            ThreadPool.QueueUserWorkItem(DownloadImage, info);
        }
예제 #5
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, int playbackPercentage, int unplayedCount, string format)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}/{7}/{8}",
                                    _serverAddress,
                                    info.ItemId,
                                    info.Type,
                                    info.ImageTag,
                                    format,
                                    maxWidth.ToString(CultureInfo.InvariantCulture),
                                    maxHeight.ToString(CultureInfo.InvariantCulture),
                                    playbackPercentage.ToString(CultureInfo.InvariantCulture),
                                    unplayedCount.ToString(CultureInfo.InvariantCulture)
                                    );

            var width  = info.Width;
            var height = info.Height;

            info.IsDirectStream = false;

            if (width.HasValue && height.HasValue)
            {
                var newSize = DrawingUtils.Resize(new ImageSize
                {
                    Height = height.Value,
                    Width  = width.Value
                }, null, null, maxWidth, maxHeight);

                width  = Convert.ToInt32(newSize.Width);
                height = Convert.ToInt32(newSize.Height);

                var inputFormat = (Path.GetExtension(info.File) ?? string.Empty)
                                  .TrimStart('.')
                                  .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                var normalizedFormat = format
                                       .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                if (string.Equals(inputFormat, normalizedFormat, StringComparison.OrdinalIgnoreCase))
                {
                    info.IsDirectStream = maxWidth >= width.Value && maxHeight >= height.Value;
                }
            }

            return(new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            });
        }
예제 #6
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int?maxWidth, int?maxHeight)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}?params=",
                                    _serverAddress,
                                    info.ItemId,
                                    info.Type);

            var options = new List <string>
            {
                info.ImageTag,
                "jpg"
            };

            if (maxWidth.HasValue)
            {
                options.Add(maxWidth.Value.ToString(_usCulture));
            }

            if (maxHeight.HasValue)
            {
                options.Add(maxHeight.Value.ToString(_usCulture));
            }

            url += string.Join(";", options.ToArray());

            var width  = info.Width;
            var height = info.Height;

            if (width.HasValue && height.HasValue)
            {
                if (maxWidth.HasValue || maxHeight.HasValue)
                {
                    var newSize = DrawingUtils.Resize(new ImageSize
                    {
                        Height = height.Value,
                        Width  = width.Value
                    }, null, null, maxWidth, maxHeight);

                    width  = Convert.ToInt32(newSize.Width);
                    height = Convert.ToInt32(newSize.Height);
                }
            }

            return(new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            });
        }
예제 #7
0
        private void AddCover(BaseItem item, BaseItem context, StubType?stubType, XmlWriter writer)
        {
            ImageDownloadInfo imageInfo = null;

            // Finally, just use the image from the item
            if (imageInfo == null)
            {
                imageInfo = GetImageInfo(item);
            }

            if (imageInfo == null)
            {
                return;
            }

            var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, "jpg");

            writer.WriteStartElement("upnp", "albumArtURI", NS_UPNP);
            writer.WriteAttributeString("dlna", "profileID", NS_DLNA, _profile.AlbumArtPn);
            writer.WriteString(albumartUrlInfo.Url);
            writer.WriteFullEndElement();

            // TOOD: Remove these default values
            var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, "jpg");

            writer.WriteElementString("upnp", "icon", NS_UPNP, iconUrlInfo.Url);

            if (!_profile.EnableAlbumArtInDidl)
            {
                if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    if (!stubType.HasValue)
                    {
                        return;
                    }
                }
            }

            AddImageResElement(item, writer, 160, 160, "jpg", "JPEG_TN");

            if (!_profile.EnableSingleAlbumArtLimit)
            {
                AddImageResElement(item, writer, 4096, 4096, "jpg", "JPEG_LRG");
                AddImageResElement(item, writer, 1024, 768, "jpg", "JPEG_MED");
                AddImageResElement(item, writer, 640, 480, "jpg", "JPEG_SM");
                AddImageResElement(item, writer, 4096, 4096, "png", "PNG_LRG");
                AddImageResElement(item, writer, 160, 160, "png", "PNG_TN");
            }
        }
예제 #8
0
        /// <summary>
        /// Adapts the html source returned by the XWiki server and makes it usable by Word using a local html file.
        /// </summary>
        /// <param name="xmlDoc">A reference to the xml dom.</param>
        public void Filter(ref XmlDocument xmlDoc)
        {
            XmlNodeList images = xmlDoc.GetElementsByTagName("img");

            foreach (XmlNode node in images)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    XmlAttribute vshapesAttr = node.Attributes["v:shapes"];
                    if (vshapesAttr != null)
                    {
                        node.Attributes.Remove(vshapesAttr);
                    }
                    //remove parameters from URLs
                    String src = node.Attributes["src"].Value.Split('?')[0];
                    //Creating an additional attribute to help identifing the image in the html.
                    XmlAttribute attr = xmlDoc.CreateAttribute(ImageInfo.XWORD_IMG_ATTRIBUTE);
                    //Adding the attribute to the xhtml code.
                    Guid imgId = Guid.NewGuid();
                    attr.Value = imgId.ToString();
                    node.Attributes.Append(attr);
                    //Adding the image to the current image list.
                    ImageInfo imgInfo = new ImageInfo();
                    imgInfo.imgWebSrc = src;
                    if (node.Attributes["alt"] != null)
                    {
                        imgInfo.altText = node.Attributes["alt"].Value;
                    }
                    manager.States.Images.Add(imgId, imgInfo);
                    //Downloading image
                    if (src == "")
                    {
                        continue;
                    }
                    if (src[0] == '/')
                    {
                        src = serverURL + src;
                    }
                    ParameterizedThreadStart pts = new ParameterizedThreadStart(DownloadImage);
                    String folder = localFolder + "\\" + localFilename + manager.AddinSettings.MetaDataFolderSuffix;
                    Object param  = new ImageDownloadInfo(src, folder, imgInfo);
                    pts.Invoke(param);
                    src = folder + "\\" + Path.GetFileName(src);
                    src = "file:///" + src.Replace("\\", "/");
                    node.Attributes["src"].Value = src;
                }
            }
        }
예제 #9
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, string format)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}/0/0",
                _serverAddress,
                info.ItemId.ToString("N"),
                info.Type,
                info.ImageTag,
                format,
                maxWidth.ToString(CultureInfo.InvariantCulture),
                maxHeight.ToString(CultureInfo.InvariantCulture)
                );

            var width = info.Width;
            var height = info.Height;

            info.IsDirectStream = false;

            if (width.HasValue && height.HasValue)
            {
                var newSize = DrawingUtils.Resize(new ImageSize
                {
                    Height = height.Value,
                    Width = width.Value

                }, 0, 0, maxWidth, maxHeight);

                width = Convert.ToInt32(newSize.Width);
                height = Convert.ToInt32(newSize.Height);

                var normalizedFormat = format
                    .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                if (string.Equals(info.Format, normalizedFormat, StringComparison.OrdinalIgnoreCase))
                {
                    info.IsDirectStream = maxWidth >= width.Value && maxHeight >= height.Value;
                }
            }

            // just lie
            info.IsDirectStream = true;

            return new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            };
        }
예제 #10
0
        public IActionResult Post([FromBody] GetImageDownloadInfoRequest request)
        {
            //Ensure that the application version exists and that the device has access to it.
            using (var connection = _connectionFactory.CreateAndOpen())
            {
                var agentVersion = connection.Get <AgentVersion>(request.Id);

                if (agentVersion == null)
                {
                    return(NotFound(new Error($"Unable to find agent version {request.Id}")));
                }

                var device = connection.Get <Device>(DeviceId);

                if (device == null)
                {
                    return(NotFound(new Error("Unable to find device")));
                }

                var application = connection.Get <Application>(device.ApplicationId);

                if (application == null)
                {
                    return(NotFound(new Error($"Unable to find application '{device.ApplicationId}'.")));
                }

                var deviceType = connection.Get <DeviceType>(application.DeviceTypeId);

                if (deviceType == null)
                {
                    return(NotFound(new Error($"Unable to find device type '{application.DeviceTypeId}'.")));
                }

                var response = new ImageDownloadInfo()
                {
                    ImageId    = agentVersion.ImageId,
                    Registry   = _registryConfig.RegistryHost,
                    AuthToken  = null, //TODO: This is where the auth token will go
                    Repository = _repositoryNameFactory.Agent,
                    Name       = agentVersion.Name,
                };

                //TODO: Add a device event for getting this token

                return(Ok(response));
            }
        }
예제 #11
0
        public IActionResult Post([FromBody] GetImageDownloadInfoRequest request)
        {
            //Ensure that the application version exists and that the device has access to it.
            using (var connection = _connectionFactory.CreateAndOpen())
            {
                var applicationVersion = connection.Get <ApplicationVersion>(request.Id);

                if (applicationVersion == null)
                {
                    return(NotFound());
                }

                var device = connection.Get <Device>(DeviceId);

                if (device == null)
                {
                    return(NotFound());
                }

                if (device.ApplicationId != applicationVersion.ApplicationId)
                {
                    return(BadRequest());
                }

                //Verify that the device has access to this *specific* version.
                var application = connection.Get <Application>(device.ApplicationId);

                if (application.ApplicationVersionId != request.Id && device.ApplicationVersionId != request.Id)
                {
                    return(BadRequest());
                }

                var response = new ImageDownloadInfo()
                {
                    ImageId    = applicationVersion.ImageId,
                    Registry   = _registryConfig.RegistryHost,
                    AuthToken  = null, //TODO: This is where the auth token will go
                    Repository = _repositoryNameFactory.FromApplication(device.ApplicationId),
                    Name       = applicationVersion.Name,
                };

                //TODO: Add a device event for getting this token

                return(Ok(response));
            }
        }
예제 #12
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int?maxWidth, int?maxHeight)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}?tag={3}&format=jpg",
                                    _serverAddress,
                                    info.ItemId,
                                    info.Type,
                                    info.ImageTag);

            if (maxWidth.HasValue)
            {
                url += "&maxWidth=" + maxWidth.Value.ToString(_usCulture);
            }

            if (maxHeight.HasValue)
            {
                url += "&maxHeight=" + maxHeight.Value.ToString(_usCulture);
            }

            var width  = info.Width;
            var height = info.Height;

            if (width.HasValue && height.HasValue)
            {
                if (maxWidth.HasValue || maxHeight.HasValue)
                {
                    var newSize = DrawingUtils.Resize(new ImageSize
                    {
                        Height = height.Value,
                        Width  = width.Value
                    }, maxWidth: maxWidth, maxHeight: maxHeight);

                    width  = Convert.ToInt32(newSize.Width);
                    height = Convert.ToInt32(newSize.Height);
                }
            }

            return(new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            });
        }
예제 #13
0
파일: DidlBuilder.cs 프로젝트: leaty/Emby
        private void AddCover(BaseItem item, BaseItem context, StubType?stubType, XmlWriter writer)
        {
            ImageDownloadInfo imageInfo = null;

            if (context is UserView)
            {
                var episode = item as Episode;
                if (episode != null)
                {
                    var parent = episode.Series;
                    if (parent != null)
                    {
                        imageInfo = GetImageInfo(parent);
                    }
                }
            }

            // Finally, just use the image from the item
            if (imageInfo == null)
            {
                imageInfo = GetImageInfo(item);
            }

            if (imageInfo == null)
            {
                return;
            }

            var playbackPercentage = 0;
            var unplayedCount      = 0;

            if (item is Video)
            {
                var userData = _userDataManager.GetUserDataDto(item, _user);

                playbackPercentage = Convert.ToInt32(userData.PlayedPercentage ?? 0);
                if (playbackPercentage >= 100 || userData.Played)
                {
                    playbackPercentage = 100;
                }
            }
            else if (item is Series || item is Season || item is BoxSet)
            {
                var userData = _userDataManager.GetUserDataDto(item, _user);

                if (userData.Played)
                {
                    playbackPercentage = 100;
                }
                else
                {
                    unplayedCount = userData.UnplayedItemCount ?? 0;
                }
            }

            var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, playbackPercentage, unplayedCount, "jpg");

            writer.WriteStartElement("upnp", "albumArtURI", NS_UPNP);
            writer.WriteAttributeString("dlna", "profileID", NS_DLNA, _profile.AlbumArtPn);
            writer.WriteString(albumartUrlInfo.Url);
            writer.WriteFullEndElement();

            // TOOD: Remove these default values
            var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, playbackPercentage, unplayedCount, "jpg");

            writer.WriteElementString("upnp", "icon", NS_UPNP, iconUrlInfo.Url);

            if (!_profile.EnableAlbumArtInDidl)
            {
                if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    if (!stubType.HasValue)
                    {
                        return;
                    }
                }
            }

            AddImageResElement(item, writer, 160, 160, playbackPercentage, unplayedCount, "jpg", "JPEG_TN");

            if (!_profile.EnableSingleAlbumArtLimit)
            {
                AddImageResElement(item, writer, 4096, 4096, playbackPercentage, unplayedCount, "jpg", "JPEG_LRG");
                AddImageResElement(item, writer, 1024, 768, playbackPercentage, unplayedCount, "jpg", "JPEG_MED");
                AddImageResElement(item, writer, 640, 480, playbackPercentage, unplayedCount, "jpg", "JPEG_SM");
                AddImageResElement(item, writer, 4096, 4096, playbackPercentage, unplayedCount, "png", "PNG_LRG");
                AddImageResElement(item, writer, 160, 160, playbackPercentage, unplayedCount, "png", "PNG_TN");
            }
        }
예제 #14
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, int playbackPercentage, int unplayedCount, string format)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}/{7}/{8}",
                _serverAddress,
                info.ItemId,
                info.Type,
                info.ImageTag,
                format,
                maxWidth.ToString(CultureInfo.InvariantCulture),
                maxHeight.ToString(CultureInfo.InvariantCulture),
                playbackPercentage.ToString(CultureInfo.InvariantCulture),
                unplayedCount.ToString(CultureInfo.InvariantCulture)
                );

            var width = info.Width;
            var height = info.Height;

            info.IsDirectStream = false;

            if (width.HasValue && height.HasValue)
            {
                var newSize = DrawingUtils.Resize(new ImageSize
                {
                    Height = height.Value,
                    Width = width.Value

                }, null, null, maxWidth, maxHeight);

                width = Convert.ToInt32(newSize.Width);
                height = Convert.ToInt32(newSize.Height);

                var normalizedFormat = format
                    .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                if (string.Equals(info.Format, normalizedFormat, StringComparison.OrdinalIgnoreCase))
                {
                    info.IsDirectStream = maxWidth >= width.Value && maxHeight >= height.Value;
                }
            }

            return new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            };
        }
예제 #15
0
        private void AddCover(BaseItem item, BaseItem context, StubType?stubType, XmlElement element)
        {
            if (stubType.HasValue && stubType.Value == StubType.People)
            {
                AddEmbeddedImageAsCover("people", element);
                return;
            }

            ImageDownloadInfo imageInfo = null;

            if (context is UserView)
            {
                var episode = item as Episode;
                if (episode != null)
                {
                    var parent = episode.Series;
                    if (parent != null)
                    {
                        imageInfo = GetImageInfo(parent);
                    }
                }
            }

            // Finally, just use the image from the item
            if (imageInfo == null)
            {
                imageInfo = GetImageInfo(item);
            }

            if (imageInfo == null)
            {
                return;
            }

            var result = element.OwnerDocument;

            var playbackPercentage = 0;
            var unplayedCount      = 0;

            if (item is Video)
            {
                var userData = _userDataManager.GetUserDataDto(item, _user).Result;

                playbackPercentage = Convert.ToInt32(userData.PlayedPercentage ?? 0);
                if (playbackPercentage >= 100 || userData.Played)
                {
                    playbackPercentage = 100;
                }
            }
            else if (item is Series || item is Season || item is BoxSet)
            {
                var userData = _userDataManager.GetUserDataDto(item, _user).Result;

                if (userData.Played)
                {
                    playbackPercentage = 100;
                }
                else
                {
                    unplayedCount = userData.UnplayedItemCount ?? 0;
                }
            }

            var albumartUrlInfo = GetImageUrl(imageInfo, _profile.MaxAlbumArtWidth, _profile.MaxAlbumArtHeight, playbackPercentage, unplayedCount, "jpg");

            var icon    = result.CreateElement("upnp", "albumArtURI", NS_UPNP);
            var profile = result.CreateAttribute("dlna", "profileID", NS_DLNA);

            profile.InnerText = _profile.AlbumArtPn;
            icon.SetAttributeNode(profile);
            icon.InnerText = albumartUrlInfo.Url;
            element.AppendChild(icon);

            // TOOD: Remove these default values
            var iconUrlInfo = GetImageUrl(imageInfo, _profile.MaxIconWidth ?? 48, _profile.MaxIconHeight ?? 48, playbackPercentage, unplayedCount, "jpg");

            icon           = result.CreateElement("upnp", "icon", NS_UPNP);
            icon.InnerText = iconUrlInfo.Url;
            element.AppendChild(icon);

            if (!_profile.EnableAlbumArtInDidl)
            {
                if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    if (!stubType.HasValue)
                    {
                        return;
                    }
                }
            }

            AddImageResElement(item, element, 160, 160, playbackPercentage, unplayedCount, "jpg", "JPEG_TN");

            if (!_profile.EnableSingleAlbumArtLimit)
            {
                AddImageResElement(item, element, 4096, 4096, playbackPercentage, unplayedCount, "jpg", "JPEG_LRG");
                AddImageResElement(item, element, 1024, 768, playbackPercentage, unplayedCount, "jpg", "JPEG_MED");
                AddImageResElement(item, element, 640, 480, playbackPercentage, unplayedCount, "jpg", "JPEG_SM");
                AddImageResElement(item, element, 4096, 4096, playbackPercentage, unplayedCount, "png", "PNG_LRG");
                AddImageResElement(item, element, 160, 160, playbackPercentage, unplayedCount, "png", "PNG_TN");
            }
        }
예제 #16
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int maxWidth, int maxHeight, string format)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}/0/{3}/{4}/{5}/{6}",
                _serverAddress,
                info.ItemId,
                info.Type,
                info.ImageTag,
                format,
                maxWidth,
                maxHeight);

            var width = info.Width;
            var height = info.Height;

            info.IsDirectStream = false;

            if (width.HasValue && height.HasValue)
            {
                var newSize = DrawingUtils.Resize(new ImageSize
                {
                    Height = height.Value,
                    Width = width.Value

                }, null, null, maxWidth, maxHeight);

                width = Convert.ToInt32(newSize.Width);
                height = Convert.ToInt32(newSize.Height);

                var inputFormat = (Path.GetExtension(info.File) ?? string.Empty)
                    .TrimStart('.')
                    .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                var normalizedFormat = format
                    .Replace("jpeg", "jpg", StringComparison.OrdinalIgnoreCase);

                if (string.Equals(inputFormat, normalizedFormat, StringComparison.OrdinalIgnoreCase))
                {
                    info.IsDirectStream = maxWidth >= width.Value && maxHeight >= height.Value;
                }
            }

            return new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            };
        }
예제 #17
0
        private ImageUrlInfo GetImageUrl(ImageDownloadInfo info, int? maxWidth, int? maxHeight)
        {
            var url = string.Format("{0}/Items/{1}/Images/{2}?tag={3}&format=jpg",
                _serverAddress,
                info.ItemId,
                info.Type,
                info.ImageTag);

            if (maxWidth.HasValue)
            {
                url += "&maxWidth=" + maxWidth.Value.ToString(_usCulture);
            }

            if (maxHeight.HasValue)
            {
                url += "&maxHeight=" + maxHeight.Value.ToString(_usCulture);
            }

            var width = info.Width;
            var height = info.Height;

            if (width.HasValue && height.HasValue)
            {
                if (maxWidth.HasValue || maxHeight.HasValue)
                {
                    var newSize = DrawingUtils.Resize(new ImageSize
                    {
                        Height = height.Value,
                        Width = width.Value

                    }, maxWidth: maxWidth, maxHeight: maxHeight);

                    width = Convert.ToInt32(newSize.Width);
                    height = Convert.ToInt32(newSize.Height);
                }
            }

            return new ImageUrlInfo
            {
                Url = url,
                Width = width,
                Height = height
            };
        }
 public int DownloadAndSaveImage([FromBody] ImageDownloadInfo downloadInfo)
 {
     return(MediaHelper.DownloadAndSaveImage(_hostingEnvironment.WebRootPath, downloadInfo.DownloadURL, downloadInfo.DownloadPath));
 }