Hello I use Universal Image Loader to load images from the device , now it works, but if the file path contains a "space character" the image does not get displayed and log records show that there is a FileNotFoundException .
I tried to open the file in a thread using java io and it opens and I can read it.
the file name :
/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20121014-WA0001.jp
when the Exception thrown
it replace the space with a %20 and this what makes the exception thrown.
My code:
ImageLoader.getInstance().displayImage(
Uri.fromFile(
new File(cursor.getString(cursor.getColumnIndex(
MediaStore.Images.Media.DATA)))).toString(),
holder.mImage);
works only when no spaces in the path ,
Any help
The other answer unfortunately isn't too clear on what fileName is so after some additional digging I managed to use local image with imageloader using:
Sample Code:
string imgPath = "/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20121014-WA0001.jpg";
String decodedImgUri = Uri.fromFile(new File(imgPath)).toString();
ImageLoader.getInstance().displayImage(decodedImgUri, imageView);
Android loading local image with space in path and with universal image loader also helped to resolve this.
I had the same problem and I found this solution.
String uri = fileName.getUri().toString();
String decodedUri = Uri.decode(uri);
ImageLoader.getInstance().displayImage(decodedUri, imageView);
Related
I have a problem when exporting my java project. It cannot find the path of my image.
File Project
src
config
image
copy.png
This is where my image is located
String image1 = "image/copy.png";
shell.setImage(new Image(display, image1));
It works before i export but when i export it and update my program it gives me an error. I tried also to use InputStream but it gives me null.
With the specified class, org.eclipse.swt.graphics.Image, you will want to create the Image with method Image(Device device, InputStream stream) and use getClass().getResourceAsStream( image1 ) to supply the inputStream containing the file. You probably need "/" at the start of your path.
Create image with this method work well.
new Image(device, getClass().getResourceAsStream(localImagePath));
I am able to show achievement images using the ImageManager from the URI method getUnlockedImageUri but for some reasons, I need to find the local path to the image because I don't want to use the ImageView and I need the actual file path to the image
The URI of Google Play Games achievement looks something like this content://com.google.android.gms.games.background/images/d2bbfba4/61 and I was hoping to be able to convert it to a File object like below:
File myFile = new File(ach.getUnlockedImageUri().getPath());
Log.i(ExConsts.TAG, "myFile.exists() = " + myFile.exists());
// returns false!
But that does not work! any idea why? or what else I should try? or even tell me if it's possible?
A content:// Uri is a clear sign that either
There is no local file
You do not have direct access to the local file
As stated in the getRevealedImageUri() Javadoc:
To retrieve the Image from the Uri, use ImageManager.
You can use ImageLoader.loadImage(OnImageLoadedListener, Uri) to get a Drawable which can be drawn onto a Canvas using Drawable.draw(Canvas).
You can convert a Drawable to a Bitmap using something similar to this answer if you'd like.
I have been wrestling with this all night . Here's the issue I am using the google places api in my android project and want to use the icons provided in the json output. I have looked at the questions already posed and they all refer to javascript. Essentially in the log file it keeps stating that it can't find the file when I attempt to access this path. I can put the uri in the browse and it show up any ideas?
the uri is http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png and heres the code it gives a warning too and when the marker is added (because its null errors out)
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
AssetFileDescriptor FDescriptor =
//getContentResolver().openFileDescriptor(uri, "r");
getContentResolver().openAssetFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = FDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
FDescriptor.close();
return image;
}
any help would be greatly appreciated
See the documentation for openAssetFileDescriptor. It doesn't handle the http scheme. You will probably either want to download this file manually and then use a method like the above to load a local file or use a library like Picasso, which will download and cache the image for you (and even load it into your ImageView).
I need to upload an image file and generate a thumbnail for the uploaded file in my JSF webapplication. The original image is stored on the server in /home/myname/tomcat/webapps/uploads, while the thumbnail is stored in /home/myname/tomcat/webapps/uploads/thumbs. I'm using the thumbnail generator class I copied from philreeve.com.
I have successfully uploaded the file with help from BalusC. But using Toolkit.getImage(), I can't access the image.
I used the uploaded file's absolute path, like so:
inFilename = file.getAbsolutePath();
The relevant code from the thumbnail generator is:
public static String createThumbnail(String inFilename, String outFilename, int largestDimension) {
...
Image inImage = Toolkit.getDefaultToolkit().getImage(inFilename);
if (inImage.getWidth(null) == -1 || inImage.getHeight(null) == -1) {
return "Error loading file: \"" + new File(inFilename).getAbsolutePath() + "\"";
}
...
}
Since I am already using the absolute path, I don't understand why it is not working. I have also used the following values for inFilename, but I always get the "Error loading file...".
/home/myname/tomcat/webapps/uploads/filename.ext
/uploads/filename.ext
But I did check the directory, and the image is there. (I uploaded using /home/myname/tomcat/webapps/uploads/filename.ext, and it works.) What is the correct path for the image in that directory? Thank you.
Update
I got the code to work by using:
Image inImage = ImageIO.read(new File(inFilename));
I still don't understand why Toolkit.getImage() does not work though.
Are you sure it's a JPEG file? Use an image viewer to make sure nothing bad happened to the file during upload (or that it was an image to begin with).
Also, use new File(inFilename).exists() to make sure the path is correct. I also suggest to print new File(inFilename).getAbsolutePath() in error messages because relative paths can hurt you.
That said, the rest of the code looks correct.
The problem is that Toolkit.getImage() does not return the image immediately. The issue is well-described in this bug report, a relevant extract of which is here:
This is not a bug. The submitter is not properly using the asynchronous
Image API correctly. He assumes that getImage loads all of the image's bits
into memory. However, it is well documented that the actual loading of
bits does not take place until a call to Component.prepareImage or
Graphics.drawImage. In addition, these two functions return before the
Image is fully loaded. Developers are required to install an ImageObserver
to listen for notification that the Image has been fully loaded. Once they
receive this notification, they can repaint the Image.
I found that the answer to this question works well:
Image image = new ImageIcon(this.getClass().getResource("/images/bell-icon16.png")).getImage();
I am having some issue trying to create image using createImage() using j2me. The prog will just hang. I am able to get input from file but I can't createImage. Does anyone have any idea?
if (filenames.exists()) {
InputStream input = filenames.openInputStream();
try { Logger.logEventInfo("READING1: " + imageName);
Image image = Image.createImage(input); //Having problem here...
Try using createImage(String name) version of the method if you are just trying to load the data from an image file. Make sure the image is a PNG, and in the resource (res) folder. The String should be in the format "/filename.png" -- note the leading slash.