public Bitmap GetGameImage(JObject gameData, string region, GameImageType imageType) { JToken game = gameData["response"]["jeu"]; switch (imageType) { case GameImageType.CoverFront: { string boxRegion = GetBoxRegion(game, region, "media_boxs2d"); string coverURL = game["medias"]["media_boxs"]["media_boxs2d"][boxRegion]?.ToString(); return(DownloadImage(coverURL)); } case GameImageType.CoverSpine: { string boxRegion = GetBoxRegion(game, region, "media_boxs2d-side"); string spineURL = game["medias"]["media_boxs"]["media_boxs2d-side"][boxRegion]?.ToString(); return(DownloadImage(spineURL)); } //case GameImageType.CoverBack: // string backCoverUrl = game["medias"]["media_wheels"]["media_wheel_wor"]?.ToString(); // return DownloadImage(backCoverUrl); case GameImageType.ClearLogo: string logoURL = game["medias"]["media_wheels"]["media_wheel_wor"]?.ToString(); return(DownloadImage(logoURL)); //case GameImageType.TitleScreen: // string titleURL = game["medias"]["media_wheels"]["media_wheel_wor"]?.ToString(); // return DownloadImage(titleURL); default: return(null); } }
/// <summary> /// Маппер объектов и их изображений. /// </summary> public Image GetGameImage(GameImageType type) { switch (type) { case GameImageType.Selected: return(GameImages[0]); } return(null); }
public virtual void SetMdMini(string path, GameImageType type, MemoryStream bitmapStream = null) { if (!File.Exists(path)) { throw new FileNotFoundException($"File Not Found: {path}"); } Bitmap image; using (var file = File.OpenRead(path)) image = new Bitmap(file); SetMdMini(image, type, bitmapStream); }
public void GameImagesAdd_Test(GameImageType type) { var gIR = new GameImagesResult(); gIR.AddFromUrl(type, new Uri("http://localhost")); switch (type) { case GameImageType.IMAGE_BOXART_BACK: case GameImageType.IMAGE_BOXART_FRONT: case GameImageType.IMAGE_BOXART_FULL: Assert.NotEmpty(gIR.Boxarts); break; case GameImageType.IMAGE_FANART: Assert.NotEmpty(gIR.Fanarts); break; case GameImageType.IMAGE_SCREENSHOT: Assert.NotEmpty(gIR.Screenshots); break; } }
public void AddFromUrl(GameImageType imageType, Uri imageUrl) { switch (imageType) { case GameImageType.IMAGE_FANART: this.Fanarts.Add(imageUrl.AbsoluteUri); break; case GameImageType.IMAGE_SCREENSHOT: this.Screenshots.Add(imageUrl.AbsoluteUri); break; case GameImageType.IMAGE_BOXART_BACK: this.Boxarts.Add(ImagesInfoFields.img_boxart_back, imageUrl.AbsoluteUri); break; case GameImageType.IMAGE_BOXART_FRONT: this.Boxarts.Add(ImagesInfoFields.img_boxart_front, imageUrl.AbsoluteUri); break; case GameImageType.IMAGE_BOXART_FULL: this.Boxarts.Add(ImagesInfoFields.img_boxart_full, imageUrl.AbsoluteUri); break; } }
public virtual void SetMdMini(Bitmap image, GameImageType type, MemoryStream bitmapStream = null, bool stretch = false) { if (type == GameImageType.MdSpine) { if (bitmapStream == null) { if (File.Exists(spinePath)) { File.Delete(spinePath); } using (var file = File.OpenWrite(spinePath)) using (var copy = new Bitmap(image)) copy.Save(file, ImageFormat.Png); } } using (var template = new SpineGen.Spine.Template <Bitmap>() { Image = GetMdMiniBitmap(bitmapStream), LogoArea = new Rectangle(type == GameImageType.MdFront ? 31 : 1, 1, type == GameImageType.MdFront ? 150 : 28, 214), LogoRotation = SpineGen.Drawing.Rotation.RotateNone, LogoHorizontalAlignment = SpineGen.Drawing.HorizontalAlignment.Middle, LogoVerticalAlignment = SpineGen.Drawing.VerticalAlignment.Middle, AspectRange = type == GameImageType.MdFront ? 0.04 : 0.01 }) { if (stretch) { template.AspectRange = 100; } template.Image.ClearRegion(template.LogoArea); using (var output = template.Process(new SystemDrawingBitmap(new Bitmap(image)))) { if (bitmapStream == null) { if (File.Exists(mdMiniIconPath)) { File.Delete(mdMiniIconPath); } } var bitmap = output.Bitmap; //Quantize(ref bitmap); template.Dispose(); if (bitmapStream == null) { using (var file = File.OpenWrite(mdMiniIconPath)) bitmap.Save(file, ImageFormat.Png); } else { bitmapStream.Seek(0, SeekOrigin.Begin); bitmapStream.SetLength(0); bitmap.Save(bitmapStream, ImageFormat.Png); bitmapStream.Seek(0, SeekOrigin.Begin); } } } }
public Bitmap GetGameImage(ScraperData gameEntry, string region, GameImageType imageType) { return(GetGameImage(gameEntry.ScrapedGameData, region, imageType)); }
public Bitmap GetGameImage(JObject gameData, string region, GameImageType imageType) { throw new NotImplementedException(); }
public Bitmap GetGameImage(JObject gameData, string region, GameImageType imageType) { return(null); }
public Bitmap GetGameImage(ScraperData gameEntry, string region, GameImageType imageType) { JObject scrapedGames = gameEntry.ScrapedGameData; string platformId = GetPlatformId(gameEntry.System); JToken game = scrapedGames["data"]["games"].Where(c => c["game_title"].ToString().Equals(gameEntry.Name["en"]) && c["platform"].ToString().Equals(platformId)) .FirstOrDefault(); string gameId = Assign <string>(game["id"]); switch (imageType) { case GameImageType.CoverFront: string boxBaseUrl = Assign <string>(scrapedGames["include"]["boxart"]["base_url"]["thumb"]); string boxName = string.Empty; if (scrapedGames["include"]["boxart"]["data"][gameId] != null) { boxName = Assign <string>(scrapedGames["include"]["boxart"]["data"][gameId] .Where(c => c["side"].ToString().Equals("front")) .FirstOrDefault()["filename"]); } if (boxName.Equals(string.Empty)) { return(null); } try { Stream boxArtData = null; using (HttpClient httpClient = new HttpClient()) { boxArtData = httpClient.GetStreamAsync($"{boxBaseUrl}{boxName}").Result; } return(new Bitmap(boxArtData)); } catch { } break; case GameImageType.CoverSpine: return(null); case GameImageType.CoverBack: return(null); case GameImageType.ClearLogo: try { Stream clearLogoData = null; using (HttpClient httpClient = new HttpClient()) { string apiKey = Encoding.ASCII.GetString(Scraper.Properties.Resources.tgdb); string logoJson = httpClient.GetStringAsync($"https://api.thegamesdb.net/v1/Games/Images?apikey={apiKey}&games_id={gameId}&filter%5Btype%5D=clearlogo").Result; //string logoJson = "{\"code\":200,\"status\":\"Success\",\"data\":{\"count\":1,\"base_url\":{\"original\":\"https://cdn.thegamesdb.net/images/original/\",\"small\":\"https://cdn.thegamesdb.net/images/small/\",\"thumb\":\"https://cdn.thegamesdb.net/images/thumb/\",\"cropped_center_thumb\":\"https://cdn.thegamesdb.net/images/cropped_center_thumb/\",\"medium\":\"https://cdn.thegamesdb.net/images/medium/\",\"large\":\"https://cdn.thegamesdb.net/images/large/\"},\"images\":{\"691\":[{\"id\":45225,\"type\":\"clearlogo\",\"side\":null,\"filename\":\"clearlogo/691.png\",\"resolution\":\"400x159\"}]}},\"pages\":{\"previous\":null,\"current\":\"https://api.thegamesdb.net/Games/Images?apikey={apiKey}&games_id=691&filter%5Btype%5D=clearlogo&page=1\",\"next\":null},\"remaining_monthly_allowance\":1473,\"extra_allowance\":0,\"allowance_refresh_timer\":2441138}"; JObject logoObject = JObject.Parse(logoJson); string spineBaseUrl = logoObject["data"]["base_url"]["original"].ToString(); if (logoObject["data"]["images"].Count() > 0) { string spineName = logoObject["data"]["images"][gameId][0]["filename"].ToString(); clearLogoData = httpClient.GetStreamAsync($"{spineBaseUrl}{spineName}").Result; } } if (clearLogoData != null) { return(new Bitmap(clearLogoData)); } } catch { } break; case GameImageType.TitleScreen: return(null); } return(null); }