In android, I’m trying to create a bitmap from a jpeg that I downloaded and copied to a drawable folder under res.
attached is my code:
public void draw(Canvas g, Resources res, int x, int y, int w, int h) {
Bitmap im = BitmapFactory.decodeResource(res, R.drawable.green_dragon);
Bitmap im = BitmapFactory.decodeFile(R.drawable.green_dragon);
g.drawBitmap(im, null, new Rect(x*w, y*h, (x*w)+w, (y*h)+h), new Paint());
}
Android does not recognize the R.drawable.green_dragon in either the decodeResource or decodeFile lines. I have also tried both refreshing and cleaning the application. Neither helped. When I looked up the image properties the type is File and the path is .jpg.
Thanks in advance for your assistance.
Only resources that are packaged with the application can be referenced using the
Robject.Anything you download must either be saved to a database or a file. I’m assuming you’ve already downloaded and saved the file. At which point you either need the a String that has the
Pathof the jpg or aFileDescriptorfor the jpg.Once you have either you can load the bitmap using:
or