As described in this question, I'm working with the Fortnite API to retrieve an image of their map and some coordinates to place a point on that map. Here's the map image, for reference. As shown in the previous question as well, the coordinate mapping problem was solved, but I was using System.Drawing. I deployed to a Linux box and that didn't work, so now I'm trying to rewrite it with SkiaSharp.
Here's my first attempt at it:
using var httpClient = new HttpClient();
await using var stream = await httpClient.GetStreamAsync(mapLocations.Images.Blank.AbsoluteUri);
var bitmap = SKBitmap.Decode(stream);
// the problem appears to happen here^
The problem here is that, for some reason, I get only part of the map image at the top (the blue section) but the rest of the image is black. It looks sort of like it didn't fully download or something like that. Am I missing something?
Here's a link to the full file this code is in, in case that helps provide any extra context.
So it turns out it was an issue with how SKBitmap.Decode(stream);
was handling the stream. I had to set stream.Position = 0;
, but because a regular Stream
doesn't support that, I had to first copy it to a MemoryStream
. Here's what I ended up with:
using var httpClient = new HttpClient();
await using var stream = await httpClient.GetStreamAsync(mapLocations.Images.POIs.AbsoluteUri);
await using var memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
memoryStream.Position = 0;
return SKBitmap.Decode(memoryStream);
I'd definitely be interested in hearing if there are better ways to handle this, but this worked for me in this case.