When I take camera images from a gallery, the images are rotated. I've read thousands of tutorials about this and how to fix it, but I'm still confused (I'm a bad programmer and beginner). I understand that to solve the problem I need to use an Exif class, but...
First, in onActivityResult, when I get URL selectedImage = data.getData(), how do I get the Path of this? Should I use Path or Name of image, and how do I get the path or name? Now, I understand Exif works with files, not bitmaps? And I must make File, and file search the path of an image: so, after I get the URL selectedImage, how do I make that file use exif? How can I get the path of the URI?
Excuse my enormous ignorance; if anyone can help me I'll be grateful!
Related
I understand that from api 29 we need to work with URI and Image id's to perform bitmap operations, but in order to migrate from image path to uri i'll need to drop real users databases and server databases, and if there is a way to avoid this i would like to try.
For example i got "FileNotFoundExeption: no content provider" error here:
BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(path)), new Rect(), options);
Thanks!
edits:
path is absolute file path like /storage/emulated/0/DCIM/Camera/20200128_122949_020.jpg
Here in code snippet i'm trying to decode image bounds, e.g. to get width and height of image on filesystem by path of image.
I'm having a trouble bringing the images from the gallery to my app.
The hard part is that, in some articles they use uri rather than path, but in others vice versa.
Plus, I'm not also sure... when I get Uri from the intent coming back, should I use cursor to get images data? (How to get Images from Cursor in android?) In some other references, they do it in the easy way, just with 'getPath()' method.
Do I need either of path or uri? or Only one of these?
I'm so confused now..
Always use Uri:
File file = new File(uri.getPath());
then
Bitmap bitmap= BitmapFactory.decodeFile(file.getAbsolutePath());
and when you have bitmap simply load it in to ImageView
imageView.setImageBitmap(bitmap);
I have to make an app to take a picture and showing geotag on it.
Even the captured image from camera or gallery has to show geotag on it for this requirement I searched a lot but I did not find any solution.
Can some one help me please?
Thanks.
This is a class for reading and writing Exif tags in a JPEG file or a RAW image file.Supported formats are: JPEG, DNG, CR2, NEF, NRW, ARW, RW2, ORF, PEF, SRW and RAF.
You can use ExifInterface to get metadata of any image and you can edit also.
For more details check here
My Problem is I am getting Image from Gallery & use BitmapFactory.decodeResource() for Convert the image into bitmap but the Problem is the Image is get in Emulator but not in Real Device, In Real Device the Bitmap value is getting null. following is my code for decode Gallery Image.
String Galleryimagepath="/mnt/sdcard/DCIM/.thumbnails/1308059312410.jpg";
bmpImage = BitmapFactory.decodeFile(Galleryimagepath);
drawable = new BitmapDrawable(bmpImage);
mRlayoutmainimage.setBackgroundDrawable(drawable);
Any Help would be appreciated.
Yashwanth is right, the path may be different between device and emulator, further, the path may different device to device as well. You'd be better off getting a content URI for the image you want and using MediaStore.Images.Thumbnails.getThumbnail() to get the bitmap you're looking for.
MediaStore.Images.Thumbnails
I think sd card path on real device is different. you might have to use something like
Environment.getExternalStorageState()
check the following link.
Find an external SD card location
I guess this question has been asked before, but I can't seem to find a proper answer/solution.
Have a note-taking app, which allows to take pictures. For that I start an intent, that starts up the built-in camera-app. So far so good.
But when I show that image in my app, it's in a much smaller format :(
The funny/weird thing is, that the camera-app did take a full-resolution picture! But for some reason I can't get the full version to show in my app???
So, when I use the standard Android Gallery app, and go to that picture, it is very obvious that it's full size (I can zoom in and see details I really can't see when I zoom in, in my own app). Also, the dimensions are really those of the original picture, taken with the 5MP camera.
In my app, they are very small. My phone has Android 2.2, but the same happens on my emulator (Android 2.1).
How should I retrieve the pictures in my app??? Tried a couple of ways, but none works :( Don't need a complete example (allthough that's very welcome), just a few clues are enough to search for myself.
Tx in advance!!
Greetingz,
Koen<
Very weird, I found the solution/answer by looking at the _ID-values that were being inserted in my own database. First I noticed that when I selected an existing image (via the build-in Android Gallery), I did get the full size image.
When I first took a picture, I got a scaled image. So where was the difference. Apparantly at the location where the _ID of the picture got stored in my database. In my case, and probably most cases, this happens in the onActivityResult procedure.
First take a look at what I initially had:
if(requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){
String timestamp = Long.toString(System.currentTimeMillis());
// get the picture
mPicture = (Bitmap)result.getExtras().get("data");
//save image to gallery
String pictureUrl = MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, getResources().getString(R.string.app_name_short), timestamp);
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(Uri.parse(pictureUrl).getLastPathSegment()));
The "insertPictureAttachment"-method does the actual inserting into the database.
Looking backwards, this was a bit weird anyway ... make a picture, so I could make an URI of it, and then get the last path segment (which is the _ID), so I could insert that into my database.
Eventually, it turns out that I can replace the above code with just one line:
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(result.getData().getLastPathSegment()));
Much shorter, and actually makes more sense ... rather than getting the info from result.getExtras().get("data"), I get my info from result.getData(), which gives the _ID of the original, full-size image.
I will do some further research on this though, cause it's not clear to me yet why I actually don't have to call MediaStore.Images.Media.insertImage(...) ... maybe I will have to if I want specific features (like a custom file location or something like that).
Greetingz,
Koen<