开发者

Can I save a picture to drawable file in android?

开发者 https://www.devze.com 2023-03-05 16:49 出处:网络
My app takes a photo from cam开发者_开发百科era and after some image processing operations I want to save it drawable file in android. It is possible ?No, you can\'t.

My app takes a photo from cam开发者_开发百科era and after some image processing operations I want to save it drawable file in android. It is possible ?


No, you can't.

You can store it into the internal memory. See the link for the details:

http://developer.android.com/guide/topics/data/data-storage.html#filesInternal


Why do you need it to be a resource of your app? You could save it to SD card or internal storage using Bitmap.compress(CompressFormat.PNG, 100, fileoutputStream);

Where fileoutputstream is obtained from something like:

String pathString = String.format("%s/%s/%s", Environment.getExternalStorageDirectory(),yourDirOnSD, yourFilename);
        File path = new File(pathString);
        path.mkdirs();

And then read it back in when you want using BitmapFactory.decodeFromFile();

Note that if the directory you use on SD starts with a period, it will be exempt from being scanned by the Android media scanner so items in it wont show up in the users photo gallery app, etc. If you want the photo to be visible to other apps, you should probably look into use MediaScanner to have it index your pic once save, otherwise it wont show up until the SD card id remounted.

0

精彩评论

暂无评论...
验证码 换一张
取 消