Exemple #1
0
        /// <summary>
        /// Gets the asset thumbnail url for a certain size.
        /// </summary>
        /// <param name="size">The size to get the thumbnail for.</param>
        /// <returns>The thumbnail to the image with the size.</returns>
        public async Task <string> GetAssetImageURL(EThumbnailSize size)
        {
            string sizeStr = "";

            switch (size)
            {
            case EThumbnailSize.Rectangle160x100:
                sizeStr = "160x100";
                break;

            case EThumbnailSize.Rectangle420x230:
                sizeStr = "420x230";
                break;

            case EThumbnailSize.Rectangle60x62:
                sizeStr = "60x62";
                break;

            case EThumbnailSize.Square100x100:
                sizeStr = "100x100";
                break;

            case EThumbnailSize.Square110x110:
                sizeStr = "110x110";
                break;

            case EThumbnailSize.Square250x250:
                sizeStr = "250x250";
                break;

            case EThumbnailSize.Square352x352:
                sizeStr = "352x352";
                break;

            case EThumbnailSize.Square420x420:
                sizeStr = "420x420";
                break;

            case EThumbnailSize.Square48x48:
                sizeStr = "48x48";
                break;

            case EThumbnailSize.Square75x75:
                sizeStr = "75x75";
                break;

            default:
                throw new ArgumentException("Size must not be Unknown.", "size");
            }

            return(await HttpHelper.GetStringFromURL(string.Format("https://www.roblox.com/Thumbs/RawAsset.ashx?assetId={0}&imageFormat=png&width={1}&height={2}", ID, sizeStr.Split('x')[0], sizeStr.Split('x')[1])));
        }
Exemple #2
0
        /// <summary>
        /// Downloads the asset's thumbnail
        /// </summary>
        /// <param name="size"></param>
        /// <returns></returns>
        public async Task <byte[]> GetAssetImage(EThumbnailSize size)
        {
            string url = await GetAssetImageURL(size);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

            req.UserAgent = "CSharp.RobloxAPI";
            WebResponse resp = await req.GetResponseAsync();

            byte[] imageBuffer = new byte[resp.ContentLength];

            await resp.GetResponseStream().ReadAsync(imageBuffer, 0, imageBuffer.Length);

            return(imageBuffer);
        }
        public static bool TryGetThumbnail(this FileInfo fileInfo, out BitmapSource bitmapSource,
                                           EThumbnailSize size = EThumbnailSize.Large)
        {
            bitmapSource = null;

            if (!ShellObject.IsPlatformSupported || fileInfo == null || !fileInfo.Exists)
            {
                return(false);
            }

            var shellItem = ShellObject.FromParsingName(fileInfo.FullName);

            try
            {
                switch (size)
                {
                case EThumbnailSize.Small:
                    bitmapSource = shellItem.Thumbnail.SmallBitmapSource;
                    break;

                case EThumbnailSize.Medium:
                    bitmapSource = shellItem.Thumbnail.MediumBitmapSource;
                    break;

                case EThumbnailSize.Large:
                    bitmapSource = shellItem.Thumbnail.LargeBitmapSource;
                    break;

                case EThumbnailSize.ExtraLarge:
                    bitmapSource = shellItem.Thumbnail.ExtraLargeBitmapSource;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(size), size, null);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }