How to create a Bitmap from an image file in Android - android

How to load an image file (on SD card) into a Bitmap on Android?

http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeFile(java.lang.String)

Related

Loading images from internal memory to an imageview

How do I display images from the phone's internal storage in an ImageView on android?
No image is loaded using the following code on my phone running on Marshmallow.
String path = Environment.getExternalStorageDirectory()+ "/MyFolder/final_photo";
File imgFile = new File(path);
if (imgFile.exists()) {
imageView.setImageBitmap(decodeFile(imgFile));
}
Your path doesn't contain a String to an Actual Image!
Images end with .jpg, .png etc.
As you also said that your Phone is on Marshmallow, you should also Allow the Storage permissions to your App!

Android can't read picture stored in phone memory, only works on pictures stored in sd card

I am creating an app that takes pictures then i read them,
when pictures are stored in SD card i can read them fine but when they are stored in phone memory i can find them (newFile displays correct path) but i don't see them in the image view. In samsung phones they are stored in /storage/emulated/0/Pictures/AppImages in cases like this is when i can't read and display in ImageView
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "AppImages");
final ImageView newImage = new ImageView(this);
File newFile = new File(mediaStorageDir+File.separator+files.getString(2));
//I have tried this 3 options one at a time
final Bitmap bmp = BitmapFactory.decodeFile(newFile.getAbsolutePath());
final Bitmap bmp = BitmapFactory.decodeStream(new FileInputStream(newFile));
final Bitmap bmp = BitmapFactory.decodeFile(newFile.getPath());
newImage.setImageBitmap(bmp);
Have you tried MediaStore?
Look at this:
MediaStore.Images.Media.EXTERNAL_CONTENT_URI //from external storage
MediaStore.Images.Media.INTERNAL_CONTENT_URI //from internal storage
Take a look at this link
The problem was i was displaying the full pictures in the gallery, resizing them to thumbnails size fixed the issue.

Save images from drawable to internal file storage in Android

I have some 10 images saved in drawable folder. I want to move them to internal file storage.
Is this possible?
I have searched a lot but, I only found links where we can save image to internal file system from given path, but I want to save images from drawable folder to internal file storage in Android and I want to achieve this through code.
Any help will greatly be appreciated.
Thank you.
Saving image to sdcard from drawble resource:
Say you have an image namely ic_launcher in your drawable. Then get a bitmap object from this image like:
Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.ic_launcher);
The path to SD Card can be retrieved using:
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
Then save to sdcard on button click using:
File file = new File(extStorageDirectory, "ic_launcher.PNG");
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Don't forget to add android.permission.WRITE_EXTERNAL_STORAGE permission.

what is the path to a drawable image so i can insert in to a file

After failing to insert a sdcard image in to a file, I want to try and insert a drawable image in to a file, anyone know the path to a drawable image? Thx
Make an object of "Bitmap" from the drawble as:
your drawble -> object of BitmapDrawble - > bitmapDrawble.getBitmap() will convert it into Bitmap.
Now write it into a file by converting it into file output stream and write in a file on your SD Card (its a standard code to accomplish this).

Store image and audio file in android internal storage

How to store image and audio files in android internal storage?
And how to retrieve back to display image in imageview?
You can write a file to your internal storage. Check this link
https://developer.android.com/guide/topics/data/data-storage.html#filesInternal
Retrieve a File
ImageView image = new ImageView();
Bitmap bMap = BitmapFactory.decodeFile("/folder/yourfilename.png");
image.setImageBitmap(bMap);

Categories

Resources