0

I am using Xamarin Forms 4.1 (android and ios) and am trying to load an image (png) from the respective asset folders (i.e. resources/drawable on android) into an SKBitmap.

I can load with no problem from the shared folder, (like so)

Assembly assembly = GetType().GetTypeInfo().Assembly;
string resourceID = "PROJECTNAME.Images.image.png";
using (Stream stream = assembly.GetManifestResourceStream(resourceID))
{
    SKBitmapObj = SKBitmap.Decode(stream);
}

but would like to do so from the platform folders as the images are used in XAML elsewhere as well.

I have attempted to first load the image into an FFImageLoading CachedImage, and then get the bytes to decode into the SKBitmap, but likewise I seem unable to load a platform image in code.

FFImageLoading.Forms.CachedImage cachedImage =
new CachedImage() { Source = "imagename" };
SKBitampObj = SKBitmap.Decode(cachedImage.GetImageAsPngAsync(60, 60).result);

CachedImages display fine when I do so in XAML, so I assume I am just addressing the image incorrectly, but am not sure.

G.E.
  • 63
  • 1
  • 7
  • `cachedImage.GetImageAsPngAsync` is an ASYNC method, try to await the result and then call `SKBitmap.Decode()`. – nevermore Jul 29 '19 at 08:25
  • Yes, its right the name of course. The issue is that I want to do this in a constructor, which is nested in several other constructors actually, so awaiting wasn't preferable. Anyway, I just went the workaround of including the graphic in the shared folder. – G.E. Jul 30 '19 at 19:55

0 Answers0