Reputation: 2033
I searched for past two days and i was not successful yet .
I my case , i want to check the camera pixel resolution/Megapixels . If the camera's Mp is more than 4 then i need to re-size and upload .
Here is my code :
//to check the resolution
Camera mcamera ;
mcamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
Camera.Parameters param = mcamera.getParameters();
Camera.Size size = param.getPictureSize();
cam_height = size.height ;
cam_width = size.width ;
mcamera.release();
// my functionality
BitmapFactory.Options resample = new BitmapFactory.Options();
if(cam_height > pict_height || cam_width > pict_width )
resample.inSampleSize = 2; // whatever number seems appropriate 2 means 1/2 of the original
else
resample.inSampleSize = 1;
capturedimg = BitmapFactory.decodeFile(fileUri.getPath() , resample);
resized_uri = bitmaptouri(capturedimg);
but this returns only the picture resolution which is the same as the Screen resolution of the mobile but i want the Mobile camera's resolution .
Any related answers are welcomed , Thanks in advance .
Upvotes: 0
Views: 3744
Reputation: 320
Try the code from here. It returns resolution in mp for back camera. You should use getSupportedPictureSize instead of getPictureSize
https://stackoverflow.com/a/27000029/1554031
Upvotes: 0
Reputation: 5803
First check the supported picture sizes available for the Camera using Camera.Parameters
. There is a function called getSupportedPictureSizes()
in Camera Parameters.
For e.g:
List<Camera.Size> mList = mParams.getSupportedPictureSizes();
Camera.Size mSize = mList.get(mList.size() - 1);
From the mList you get all the supported Picture Sizes. The final one in the list will be the largest possible resolution.
Upvotes: 0
Reputation: 12733
First find height and width like below:
android.hardware.Camera.Parameters parameters = camera.getParameters();
android.hardware.Camera.Size size = parameters.getPictureSize();
int height = size.height;
int width = size.width;
then get mega pixel using below equation:
int mg = height * width / 1024000;
where mg is your mega pixels.
Upvotes: 1