Reputation: 105
Okay so I am making an app to play Blackjack for a class on Android, and am visually displaying the cards. I would like to use the BitmapRegionDecoder to be most efficient at loading my cards, which are all displayed in one file. Here's my code:
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance("res/drawable/cards.png", false);
Bitmap img = decoder.decodeRegion(new Rect(num, suit, num + 1, suit + 1), null);
I know that "res/drawable/cards.png" is not the right way to give the path due to all of the error messages I get, but I don't know what I should use for the path instead. Please help, and thank you! :)
Upvotes: 1
Views: 950
Reputation: 687
Use newInstance (InputStream is, boolean isShareable) method instead :
InputStream is = getResources().openRawResource(R.drawable.cards)
BitmapRegionDecoder regionDecoder = BitmapRegionDecoder.newInstance(is, false);
Upvotes: 2