我正在开发一款带有相机SurfaceView的应用程序。我想在横向和纵向模式下拍摄风景图像。由于我在代码中使用了camera.setDisplayOrientation(90);
,因此预览显示正常。
然而,当我拍摄图像时,它会旋转显示。我可以再次旋转它,但一旦完成就会变成肖像。有谁知道如何从相机拍摄风景图像?
这是我配置相机参数的方式
private void configure() {
Camera.Parameters params = camera.getParameters();
// Configure image format. RGB_565 is the most common format.
List<Integer> formats = params.getSupportedPictureFormats();
if (formats.contains(PixelFormat.RGB_565))
params.setPictureFormat(PixelFormat.RGB_565);
else
params.setPictureFormat(PixelFormat.JPEG);
// Choose the biggest picture size supported by the hardware
/*List<Camera.Size> sizes = params.getSupportedPictureSizes();
Camera.Size size = sizes.get(sizes.size()-1);
params.setPictureSize(size.width, size.height);*/
params.setPictureSize(Constants.IMAGE_WIDTH, Constants.IMAGE_HEIGHT);
List<String> flashModes = params.getSupportedFlashModes();
if (flashModes.size() > 0)
params.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
// Action mode take pictures of fast moving objects
List<String> sceneModes = params.getSupportedSceneModes();
if (sceneModes.contains(Camera.Parameters.SCENE_MODE_ACTION))
params.setSceneMode(Camera.Parameters.SCENE_MODE_ACTION);
else
params.setSceneMode(Camera.Parameters.SCENE_MODE_AUTO);
// if you choose FOCUS_MODE_AUTO remember to call autoFocus() on
// the Camera object before taking a picture
params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
camera.setParameters(params);
}
这就是我拍摄图像的地方
private void takePicture()
{
configure();
camera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
camera.takePicture(shutterCallback, pictureCallback_RAW, pictureCallback_JPEG);
}
});
}
这是保存从相机拍摄的图像的地方
PictureCallback pictureCallback_JPEG = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
File storageDirectory = CameraHelper.getStorageDirectory();
String fileName = CameraHelper.getStorageFileName();
imagePath = storageDirectory.getPath()+File.separator+fileName;
File output = new File(storageDirectory, fileName);
try {
FileOutputStream fos = new FileOutputStream(output);
fos.write(data);
fos.close();
imageCapturedState=true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
这是我拍照时的相机预览
这是保存后的显示方式(预览中的图像旋转90度。)
如你所见,我可以旋转图像,但一旦完成它就会变成肖像。如何在不进行鼠标训练的情况下保存风景图像?谢谢!