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.
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!
I am working with a customizable database with pictures. Right now I am taking pictures as it is from the sdcard and encoding it in base64 String and then putting it in the database. but whenever I am trying decoding it and showing it in my view, I am getting Out of memory error. Can any one one tell me what is the best procedure to do it? Shall I change the size of the pictures before encoding it?
I want to re-size all of the pictures into 512*512.
Image to Base64 is very heavy operation in android. Consider saving the images on the external/internal memory and save the file path in the sqlite database.
You can convert your image to byte array then store values in sql by using BLOB type and vice versa.
As you mentioned you want to resize the images to 512*512, you can scale the image using below code,
Create bitmap from captured image and then use below line
Bitmap resizedBitmap = Bitmap.createScaledBitmap(myBitmap, 512, 512, false);
It will give you a smaller image, you can also consider compressing the image to reduce in size,
OutputStream imagefile = new FileOutputStream("/your/file/name.jpg");
// Write 'bitmap' to file using JPEG and 50% quality hint for JPEG:
bitmap.compress(CompressFormat.JPEG, 50, imagefile);
Now, you have two options,
Save the scaled and compressed image into a file and save the path of that file in db. (Better way)
Convert the scaled and compressed image to base64 string and save in db.
Althought base64 is , as many answers said, a heavy operation for android, if done properly, it should not be a problem.
There are many reasons a bitmap could be required to be saved to a DB , (photo of a invoice ticket, for example?), and this is the way i do it.
first, create a new , smaller bitmap like #Swapnil commented.
and second, correctly use the bitmap transformation methods, i've been using these (look below) two so far and haven't had any memory issue on many different devices.
link to my BitmapUtils transformation methods
I already know how to use PHP+MySQL to get the URL path of image and turn it to a bitmap in android. But now I want to get the images from another way. If the image is stored by relative-path in MySQL, how can I turn it to a bitmap?
Are there any tutorials or demos?
String picPath = "/mnt/sdcard/yepcolor/sina.png";
Bitmap bitmap = BitmapFactory.decodeFile(picPath);
I know the 'picPath' of the picture.Now, I want to get the picture's shooting time,and what should I do?Thanks.
As far as I know, png files doesn't contain such information. If you are reading jpeg files, however, you can use ExifInterface.