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);
Related
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!
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.
I created android app which reads images from url. Now I want to store those images in local file structure or SD Card. so i created a folder names "images" in my android project and added image xyz.png manually to test reading of images.
and wrote below code to read.
Bitmap bMap = BitmapFactory.decodeFile("/images/xyz.png");
ImageView imgView = (ImageView) this.findViewById(R.id.imgViewId);
imgView.setImageBitmap(bMap);
But eclipse says unable to find the resource!!
What is the best way to store and read images in android app?
I did caching but cache get clears if i force close the app.
I want to store in android mobile/tablet and it should be part of app.
try the enviroment variable to get the directoty
Bitmap bMap = BitmapFactory.decodeFile("/images/xyz.png");
Bitmap bMap = BitmapFactory.decodeFile(Environment.getRootDirectory()+"/images/xyz.png");
give a try to this ....
private String filepath = "MyFileStorage";
ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
File directory = contextWrapper.getDir(filepath, Context.MODE_PRIVATE);
myInternalFile = new File(directory , "abc.png");
FileOutputStream fos = new FileOutputStream(myInternalFile);
bMap.compress(CompressFormat.PNG, 90, fos); //output image is the image bitmap that you obtain
Check this android description
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.
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)