i am downloaded and saved images from web to my app cache folder. Now i am trying to convert particular cache folder image(PREM.jpg) into bitmap. For that i am using bellow code.
FileCache file = new FileCache(Context);
File f = file.getFile("PREM.jpg");
Bitmap bitmap = decodeFile(f);
System.out.println("Exist status. " + f.exists());
But i am always getting file not exist (Exist status. false).
Actually "PREM.jpg" file name showing some thing like "-1006685176" in the cache folder.
This is my cache filder
Can you please help me how to i convert that particular image into bitmap.
Thank you everyone.
Prem
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 have a trouble with load image file in android project. I need to load from it because I have some private reasons.
here is my android project structure:
ProjectAA
----assets
----image
--------ic_next.png
----src
--------HomeActivity.java
----AndroidManifest.xml
I tried to load ic_next.png in HomeActivity.class with:
InputStream is = getClass().getClassLoader().getResourceAsStream("image/ic_next.png");
Bitmap bm = BitmapFactory.decodeStream(is);
but bm always return null. I also add "image" folder to java build path
I searched google but I can't find any solution. please help me.
Thanks
Put image folder under src folder or include image folder as source folder in project settings.
I'm having troubles adding a local image to the disk cache manually. The reason is that I have a local photo and I need to upload this. But since I know the URL result, I want to cache this immediately. I'm using
ImageLoader.getInstance().getDiscCache().put(imageUrl, new File(tempFileURI));
But this doesn't work because when I use the line below, the file returns null
File thumb=
DiscCacheUtil.findInCache(urlThumbSize,ImageLoader.getInstance().getDiscCache());
Any idea?
Actually DiscCache is not intended to be used directly. DiscCache.put() doesn't copy your file into disk cache. It just control cache size if it's limited cache.
You should copy image file into cache directory yourself:
File fileInDiscCache = discCache.get(imageUri);
// copy your file into 'fileInDiscCache' file
discCache.put(imageUri, fileInDiscCache);
My webview saves lot of cache on SD Card when I visit a site which contains images and they don't show their format. When I try to open them, the default Android file manager says "File type not found". Then I changed the format of some of them(mostly the big size one) to .jpg and bingo, they are the images I saw on the webpage.
Punchline: I want to open the images from that sites that are saved as cache, in another activity, would I have to go on and rename all the cache files to .jpg then call them or there is another way to do it.
Thank you.
You can use the BitmapFactory to open these images files. You can try:
- decodeFile(String pathName)
If it gives some problem with the extension, try decodeStream (InputStream is), it receive an InputStream and it should work.
You can list a folder with File:
File f = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath());
File[] files = f.listFiles();
for (File file : files){
//Do something with this file
}
I'm attempting to create a gallery/gridview that is loaded with images from a specific folder that resides on an SDCard. The path to the folder is known, ("mnt/sdcard/iWallet/Images") , but in the examples I've seen online I am unsure how or where to specify the path to the pictures folder I want to load images from. I have read through dozens of tutorials, even the HelloGridView tutorial at developer.android.com but those tutorials do not teach me what i am seeking.
Every tutorial I have read so far has either:
A) called the images as a Drawable from the /res folder and put them into an array to be loaded, not using the SDCard at all.
B) Accessed all pictures on the SDCard using the MediaStore but not specifying how to set the path to the folder I want to display images form
or
C) Suggested using BitmapFactory, which I haven't the slightest clue how to use.
If I'm going about this in the wrong way, please let me know and direct me toward the proper method to do what I'm trying to do.
my target android sdk version 1.6...
thanks..
You can directly create Bitmaps from decodeFile (String pathName) that will give you Bitmap object that can be set on ImageView
Update: Below is sudo code with minor errors modify it to suit your needs
File path = new File(Environment.getExternalStorageDirectory(),"iWallet/Images");
if(path.exists())
{
String[] fileNames = path.list();
}
for(int i = 0; i < fileNames .length; i++)
{
Bitmap mBitmap = BitmapFactory.decodeFile(path.getPath()+"/"+ fileNames[i]);
///Now set this bitmap on imageview
}
Actually, you are wrong to mention fixed path to access SD-card directory, because in some device it is /mnt/sdcard and in other /sdcard.
so to access root directory of sd-card, use the getExternalStorageDirectory(), it gives you actual path of root directory.
This function will resturn all the files from specific folder you need to pass path till ur folder
public static List getFilesFromDir(File aStartingDir)
{
List result = new ArrayList();
File[] filesAndDirs = aStartingDir.listFiles();
List filesDirs = Arrays.asList(filesAndDirs);
Iterator filesIter = filesDirs.iterator();
File file = null;
while ( filesIter.hasNext() ) {
file = (File)filesIter.next();
result.add(file); //always add, even if directory
if (!file.isFile()) {
//must be a directory
//recursive call!
List deeperList = getFileListing(file);
result.addAll(deeperList);
}
}
Collections.sort(result);
return result;
}
BitmapDrawable d = new BitmapDrawable(getResources(), path+".jpg"); // path is ur resultant //image
img.setImageDrawable(d);
Hope it help u...
You can access your directory using File java class, then iterate through all the files in there, create a bitmap for each file using Bitmapfactory.decodeFile() then add the bitmaps to your gallery.