Closed WolfgangRoggen closed 3 years ago
Check this piece of code: https://github.com/LordMike/TMDbLib/blob/d96b460d2867e8d93a2cfb9c84d9eedfcf633b21/TestApplication/Program.cs#L97-L118
Mike.
Hello Mike,
thx fort he code, but thats are basics and I already know.
What i need is, if I have for exaple the PosterPath form yor example:
With this code
Uri imageUri = client.GetImageUrl(size, imageData.FilePath);
I get
http://image.tmdb.org/t/p/w300/uhYoytlNaq46dG81wLmHqaSuzWu.jpg
what I need ist to get this specific Image so I can convert it to an bytearry to store it in a database or Bitmapsource to display it on a screen or…
I hope i can explain what i mean?
Wolfgang
Von: Michael Bisbjerg @.> Gesendet: Freitag, 26. März 2021 18:54 An: LordMike/TMDbLib @.> Cc: Author @.>; WolfgangRoggen @.> Betreff: Re: [LordMike/TMDbLib] Get Image via path e.g. PosterPath (#367)
Check this piece of code: https://github.com/LordMike/TMDbLib/blob/d96b460d2867e8d93a2cfb9c84d9eedfcf633b21/TestApplication/Program.cs#L97-L118
Mike.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808410430 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5IQNXLD6Z27MCO5X7MT2TTFTC2TANCNFSM4Z3LBIMQ . https://github.com/notifications/beacon/AH5IQNVEZ5CW3PP3IOZ5TPTTFTC2TA5CNFSM4Z3LBIM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGAXV2PQ.gif
[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808410430", "url": "https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808410430", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]
Oh - but once you have the URL, can't you download it with an HttpClient?
I could add a method to fetch it...
Surely, but I’m thinking it should be a a part of your wrapper to make it complete.
Otherwise it needs a 2nd HttpClient and you have already one.
I’ve checked it and i made a solution. But I‘m no expert in http programming. So could be there is a better solution:
public async Task<byte[]> GetImageByPathAsync(string path, string imageSize)
{
if (string.IsNullOrWhiteSpace(path))
{
return null;
}
try
{
Uri uri = GetImageUrl(imageSize, path);
string url = uri.ToString();
// _client = TMDbClient
RestRequest req = _client.Create(url);
var resp = await req.ExecuteGet(CancellationToken.None).ConfigureAwait(false);
using (Stream stream = await resp.GetContent().ConfigureAwait(false))
{
Image image = Image.FromStream(stream);
ImageConverter imageConverter = new ImageConverter();
//the conversion is needed, because the image exists only as long the stream is alive
byte[] array = (byte[])imageConverter.ConvertTo(image, typeof(byte[]));
return array;
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
And in private async Task
you have ta add
switch (resp.StatusCode)
{
// if we have no Json, e. g. from GetImageByPathAsync(…)
case (HttpStatusCode.OK):
return resp;
Von: Michael Bisbjerg @.> Gesendet: Samstag, 27. März 2021 11:59 An: LordMike/TMDbLib @.> Cc: Author @.>; WolfgangRoggen @.> Betreff: Re: [LordMike/TMDbLib] Get Image via path e.g. PosterPath (#367)
Oh - but once you have the URL, can't you download it with an HttpClient?
I could add a method to fetch it...
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808711764 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5IQNVDEO5EGUGAO3S4EOTTFW3APANCNFSM4Z3LBIMQ . https://github.com/notifications/beacon/AH5IQNXHQYRVMXYDXQQSRFTTFW3APA5CNFSM4Z3LBIM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGAZ7MVA.gif
[ { @.": "http://schema.org", @.": "EmailMessage", "potentialAction": { @.": "ViewAction", "target": "https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808711764", "url": "https://github.com/LordMike/TMDbLib/issues/367#issuecomment-808711764", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { @.": "Organization", "name": "GitHub", "url": "https://github.com" } } ]
I've added a function to download the images. Let me know if it works out for you :).
Hi,
how can I get a Image set in the path property?
regards Wolfgang