Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture a custom image size with the camera in android?

How to capture an square image in android? I want to capture an square image (such as 300x300 pixel) by calling Camera through intent in android, how can I do this?

like image 845
Nguyen Minh Binh Avatar asked Apr 25 '11 03:04

Nguyen Minh Binh


People also ask

How do you change the size of a picture on Android?

Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.

What is captured image size?

Image size: This represents the physical size and resolution of an image measured in pixels. For example, A 10 megapixel (MP) camera may provide settings to take pictures in 10.2 MP (3872 x 2592), 5.6 MP (2896 x 1944), and 2.5 MP (1936 x 1296). A higher image size setting means a larger picture and bigger file size.


1 Answers

EDIT: This is deprecated since API level 21.

Use the Camera.Size nested class

http://developer.android.com/reference/android/hardware/Camera.Size.html

From the android reference:

http://developer.android.com/reference/android/hardware/Camera.html

Class Overview

The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. This class is a client for the Camera service, which manages the actual camera hardware.

Make sure that the size is supported by the camera (and most probably it won't). If not, take a picture at the closest resolution and crop it or resize it.

Camera myCamera = Camera.open(0);
List<Camera.Size> sizes = myCamera.getPArameters().getSupportedPictureSizes();

To learn about camera intents, check these questions already in SO:

Android camera intent

Camera intent android

like image 136
Aleadam Avatar answered Oct 02 '22 22:10

Aleadam