0

This is very much a noob question.

With the benefit of this answer from a different question, I have created a class which theoretically takes a BMP image and resizes it to the size of the image, rather than the (blank) background.

However, I can't work out how to run the class and reference an image which is saved as a drawable.

I've tried

package com.example.trimmer_test;
import android.media.Image;
public class Activity_main {
"@drawable/imagename"
}

After some searching, I thought that I had to use the getResource method to import the image, so I tried

package com.example.trimmer_test;
import android.media.Image;
public class Activity_main {
Activity_main.getResource("@drawable/imagename")
}

But this brings up a "cannot resolve symbol 'getResource'" error.

I've tried what feels like a million variants of this and can't figure it out.

Apologies for what I imagine is a basic question, but I have searched thoroughly and can't find the answer anywhere.

Statsanalyst
  • 331
  • 2
  • 3
  • 16

1 Answers1

0

You can try this out.

ContextCompat.getDrawable(this, R.drawable.your_image_name)

PBKN
  • 45
  • 5
  • Thanks for the answer. I get error "cannot resolve symbol "ContextCompat" – Statsanalyst Sep 29 '20 at 18:17
  • [Google dev docs for ContextCompat](https://developer.android.com/reference/android/support/v4/content/ContextCompat.html) You can also use getContext() instead. – PBKN Sep 30 '20 at 04:09