0

I'm writing a NativeScript plugin for the Stripe library. On Android, I can't figure out how to turn a resource ID from the native library into a drawable image.

One of the calls I make returns an ID obtained from R.drawable.xxx. The image is in the native library's resources. I want to turn that into an image I can draw using the tag.

I have tried this code:

import { android as androidApp } from "application";
let res = ...; // obtained from native library
let image = android.graphics.BitmapFactory.decodeResource(
  androidApp.foregroundActivity.getResources(),
  res);

but decodeResource() returns null. The native library is able to draw the same image, so somehow the resource is getting into the app. I just don't know how to access it from my code.

Note: On iOS this same call returns a UIImage, which is working correctly. I wish Stripe had been more consistent between their iOS and Android APIs!

RDG
  • 63
  • 7

1 Answers1

1

I figured out the problem. Turns out my diagnosis was incorrect. The resource was being found, but it was a VectorDrawable and decodeResource() is unable to properly decode it.

The technique for converting a VectorDrawable to a Bitmap posted in this question works.

RDG
  • 63
  • 7