Bitmap and proper saving location

168
May 07, 2018, at 11:23 PM

Hi everybody I've got the following problem with an adroid app: I want to read an image saved and perform some operations on it. (I do not need to use this image to draw something on screen, I just have to check the color of some pixels)

I'm using the following code:

Bitmap bitmap = BitmapFactory.decodeFile("drawable-v24/ean13.bmp");

The fact is that the BitmapFactory returns null as a FileNotFoundException is thrown. (by now the file is saved inside res folder)

I don't really understand where I should put the image and how to give the path to the BitmapFactory to be able to get it properly.

(I guess the problem is due to the fact that the image actually is stored on my pc and not on the Android device but I can't understand how should I proceed)

Thank you in advance for the help! :)

Answer 1

If you are accessing image from resource drawable of mipmap. You should use BitmapFactory.decodeResource to get Bitmap.

Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);

Or another overloaded version .

public static Bitmap decodeResource(Resources res, int id, Options opts)

where getResources() is method of Activity.

Rent Charter Buses Company
READ ALSO
shared transition from activity's fragment's listview's custom base adapter button click to another activity is not working

shared transition from activity's fragment's listview's custom base adapter button click to another activity is not working

I am using listview with custom BaseAdapter to display various itemThe listview is inside FragmentA and FragmentA is displayed using MainActivity's view pager

150
combine tab view with bottom navigation

combine tab view with bottom navigation

In my app I want to combine a tabView with a bottom navigation barI want to have three tabs and three options in the bottom bar, so there should be nine different activities in the end

189
How to identify if an outgoing call is placed through my app?

How to identify if an outgoing call is placed through my app?

In my app there is a call functionality inside a fragmentNow when the call gets disconnect and my app comes to foreground I want to ask user that whether the call was placed successfully or not

195
Why the Firebase Model is not populating the layout?

Why the Firebase Model is not populating the layout?

I am creating a chat App, using FirebaseDatabase, but there is a problem retrieving the message,however user is able to push the message

233