How to capture low resolution picture using android camera - android

I want to capture photo and also save it to my sdcard using android camera.I know its easy but I want to store image in low resolution without telling user go to setting and set low resolution manually.

What i am gonna write is not good practice to do code but it may full-fill your requirement
capture image as you do with normally using android default camera .
check the path of that image which just now captured .
reduce quality of that image as per requirement using BitmapFactory.Options calss and store in bitmap object
delete that original image which captured by default camera
save that bitmap object to SD Card where old image was located with same file name and path

I know this is very late but this is for the people who might read this question now , you can use this following code :
Camera.Parameters parameters = mcamera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
Camera.Size size = sizes.get(sizes.size()-1);
Log.d("Parth","Size : "+size.height+","+size.width);
Log.d("Parth","Sizes:"+sizes.toString());
parameters.setPictureSize(size.width,size.height);
mcamera.setParameters(parameters);

Implement a camera app by yourself. Use BitmapFactory to decode raw data. Via BitmapFactory.Options, you can set any resolution you want.

Use this to capture image :
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.ACTION_IMAGE_CAPTURE, preinsertedUri);
Don't use MediaStore.EXTRA_OUTPUT because the image will be big size if you use EXTRA_OUTPUT

Related

Android BitmapFactory.decodeByteArray get the photo width/height is exchanged than iOS UIImage(data:)

I get a base64 string from the server, then I parse it to image, on Android side, the image is rotated to 270 degree, its width/height is exchanged than iOS side. Any idea? Thank you. Here is the code:
Android code:
val decodedByteArray: ByteArray = Base64.decode(base64Str, Base64.DEFAULT)
val bitmap = BitmapFactory.decodeByteArray(decodedByteArray, 0, decodedString.size)
Timber.i("image size: ${bitmap.width}, ${bitmap.height}")
iOS code:
if let photoData = Data(base64Encoded: base64Str, options: .ignoreUnknownCharacters),
let photo = UIImage(data: photoData) {
printLog("photo size: \(photo.size)")
cell.ivPhoto.image = photo
}
Check if your image has a rotation angle in its EXIF tag.
The Bitmapfactory does not perform any EXIF rotations/transformations at all.
Use the ExifInterface class to get such information. Remember to use the AndroidX variant instead of the deprecated framework one.
If such is the case, then you must rotate the image according to the EXIF angle.
This operation will require to create a new bitmap, therefore in order to avoid a potential OutOfMemoryError, use some of the tips provided in this link.
Check the image base64 data using any base64 to the image viewer. If it's same as uploaded. Then that might the android thing which rotates the image when it converts to base64 to image. So when you convert base64 to image you can rotate the image to a specific angle or portrait.
Android Bitmapfactory does rotate nothing.
Its the used ios code that rotates to original position using orientation information.
For example BitmapFactory does not look at orientation information in a jpg. The image can come in any position and orientation information is needed to put it in right orientation.
So in this case Android/BitmapFactory does not rotate or exchange anything.

Take photo of given size Android

I'm developing an application that takes a photo and saves it in Android/data/package/files. I would like to reduce storage used, so I would like to resize the photo before saving it. For the moment I'm calling new intent passing as extra the output path. Is possible to pass also the size wanted or is possible to have the bitmap before saving it?
public void takePicture(View view){
Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(getPath(nameEdit.getText().toString()));
path = f.getAbsolutePath();
pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
if (pictureIntent.resolveActivity(getPackageManager())!=null){
startActivityForResult(pictureIntent,REQUEST_IMAGE_CAPTURE);
}
}
Is possible to pass also the size wanted
No.
is possible to have the bitmap before saving it?
Not really. You could write your own ContentProvider and use a Uri for that, rather than a file. When the camera app tries saving the content, you would get that information in memory first. However, you will then crash with an OutOfMemoryError, as you will not have enough heap space to hold a full-resolution photo, in all likelihood.
You can use BitmapFactory with inSampleSize set in the BitmapFactory.Options to read in the file once it has been written by the camera, save the resized image as you see fit, then delete the full-resolution image. Or, skip EXTRA_OUTPUT, and you will get a thumbnail image returned to you, obtained by calling getExtra("data") on the Intent passed into onHandleIntent().

Android :To stored captured image in android that must be same size in every devices

Is it possible to store captured image from camera into Sdcard that shold be 50kb only and it should be same sized when i am capturing image from different different devices.
Put this code
Parameters parameters = camera.getParameters();
parameters.set("jpeg-quality", 70);
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.setPictureSize(2048, 1232);
camera.setParameters(parameters);
Set this parameters , not sure but may be this can help you ...

how to specify size of photo in camera capture in android phone

I want that my camera to capture specified size of images, I am opening camera in my application using Camera Intent in android. please give me guide lnes
Thanks
Use Camera.Size to specify the dimensions for pictures:
http://developer.android.com/reference/android/hardware/Camera.Size.html
Possibly, you may need to crop the image to be captured by your camera if not fitted:
How to crop an image in android?
try to set setPictureSize on the camera parameters
Parameters parameters = camera.getParameters();
parameters.set("jpeg-quality", 70);
parameters.setPictureFormat(PixelFormat.JPEG);
parameters.setPictureSize(2048, 1232);
camera.setParameters(parameters);
Check this:
Camera intent with resolution parameters in Android

How to get the picture's shooting time in android development?

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.

Categories

Resources