使用以下代码垂直显示相机的预览并且它可以工作..但是!我拍了一张风景照!:(
我如何垂直构建它?我有垂直的预览视图,但我无法垂直保存图片。
问候和感谢,弗兰
点击
public void onClick(View arg0) {
camera.takePicture(myShutterCallback, myPictureCallback_RAW, myPictureCallback_JPG);
}
预览
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (previewing) {
camera.stopPreview();
previewing = false;
}
if (camera != null) {
/*
* camera.setPreviewDisplay(surfaceHolder); camera.startPreview();
* previewing = true;
*/
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewSize(width, height);
camera.setParameters(parameters);
// Condicions per utilitzar la orientacio adecuada segons el sdk
if (Integer.parseInt(Build.VERSION.SDK) >= 8)
setDisplayOrientation(camera, 90);
else {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
parameters.set("orientation", "portrait");
parameters.set("rotation", 90);
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
parameters.set("orientation", "landscape");
parameters.set("rotation", 90);
}
camera.setParameters(parameters);
}
// camera.startPreview();
previewing = true;
}
}
拍照
PictureCallback myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
// intentar canvia horientacio
Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
//bitmapPicture.
OutputStream imageFileOS;
try {
imageFileOS = new FileOutputStream(String.format("/sdcard/DCIM/iboo/captura.jpg"));
imageFileOS.write(arg0);
imageFileOS.flush();
imageFileOS.close();
// Missatge en cas de capturar l'imatge correctament
Toast.makeText(Principal.this, "Imatge Capturada!",
Toast.LENGTH_LONG).show();
MostrarFoto("/sdcard/DCIM/iboo/captura.jpg");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// camera.startPreview();
}
};