Unresolved reference: vectorResource and imageResources in Jetpact Compose 1.0.0-beta07

Viewed 1506

I was using jetpack compose 1.0.0-alpha 11. The below code works.

Image(
  imageResource(R.drawable.header),
  contentDescription = null,
  modifier = itemModifier,
  contentScale = ContentScale.Crop
)

However in jetpack compose 1.0.0-beta07, imageResource and vectorResource no longer works.

What's the new way of getting the image resources?

3 Answers

With 1.0.x you can use the painterResource function:

 Image(painterResource(R.drawable.ic_xxxx),"content description")

This can load either an instance of BitmapPainter or VectorPainter for ImageBitmap based assets or vector based assets respectively.
This method works with images (PNG or JPG files) or VectorDrawable xml assets.

About the usage of ImageBitmap.imageResource(R.drawable.header)

This function is intended to be used for when low-level ImageBitmap-specific functionality is required. For simply displaying onscreen, the vector/bitmap-agnostic painterResource is recommended instead.

You can easily access drawable resouces by using painterResource.

Image(painter = painterResource(id = R.drawable.someVector), contentDescription = null)

I found we can continue to use vectorResource and imageResource using the extension of ImageVector and ImageBitmap

e.g.

Image(
  ImageBitmap.imageResource(R.drawable.header),
  contentDescription = null,
  modifier = itemModifier,
  contentScale = ContentScale.Crop
)
Related