SurfaceView上人像中的Android摄像头
我尝试了几种方法,试图让相机预览在SurfaceView上人像中的Android摄像头,android,Android,我尝试了几种方法,试图让相机预览在SurfaceView上以纵向显示。什么都没用。我正在测试一个2.0.1版本的机器人。我试过: 1) 通过以下方式强制布局为纵向:this.setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向) 2) 使用 还有什么我可以试试的吗?如果这是安卓或手机中的一个bug,我如何确保这是一个bug,以便我有证据通知客户 谢谢, Prasanna在许多当前设备上都无法做到这一点,包括G1和Droid。请
SurfaceView
上以纵向显示。什么都没用。我正在测试一个2.0.1版本的机器人。我试过:
1) 通过以下方式强制布局为纵向:this.setRequestedOrientation(ActivityInfo.SCREEN\u ORIENTATION\u横向)代码>
2) 使用
还有什么我可以试试的吗?如果这是安卓或手机中的一个bug,我如何确保这是一个bug,以便我有证据通知客户
谢谢,
Prasanna在许多当前设备上都无法做到这一点,包括G1和Droid。请在此处查看相关的错误报告:
另请参见Android工程师之一(Dave)的评论:
我有一个在2.1中工作的肖像模式的工作解决方案(在Desire上测试),可能更少
活动屏幕方向设置为纵向。
(android:screenOrientation=“肖像”)
摄像机参数:
Camera.Parameters p=mCamera.getParameters()
图像将是肖像
用于相机的SurfaceHolder的大小必须与手机预览大小兼容
通常是屏幕分辨率
欲望2.2上的搞笑功能不起作用。。。
以下是修复方法:
At surfaceCreated(..) or when you have this line
camera = Camera.open();
add
camera.setDisplayOrientation(90);//only 2.2>
Camera.Parameters p = camera.getParameters();
p.set("jpeg-quality", 100);
p.setRotation(90);
p.setPictureFormat(PixelFormat.JPEG);
p.setPreviewSize(h, w);
camera.setParameters(p);
Roman给出的问题线程链接有一个可行的解决方案,我现在正在使用
在这里找到它:
在需要明确设置方向之前,无需为方向设置任何参数。默认情况下,它支持此功能。在我的例子中,我有一个活动,在该活动之上我有一个摄影机视图,因此我没有为摄影机属性设置任何方向,而是为活动在清单文件中将方向设置为纵向。现在,该应用程序看起来和工作良好。可能对某人有帮助
谢谢。自API第8级起,该软件可用于:
公共最终无效设置显示方向(整数度)
i、 e.在舱单上注明:
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
mCamera.setDisplayOrientation(90);
您可以试试这个(适用于2.2或更低版本)。在这里,我旋转图像,然后将其保存到sd卡。但它仅适用于纵向模式。若你们必须在这两种模式下都使用,那个么你们应该检查相机的方向,并在拍摄图像之前做一些检查
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
imageFilePath = getFilename();
InputStream is = new ByteArrayInputStream(data);
Bitmap bmp = BitmapFactory.decodeStream(is);
// Getting width & height of the given image.
if (bmp != null){
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rotatedBMP.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
outStream = new FileOutputStream
(String.format(imageFilePath,System.currentTimeMillis()));
outStream.write(byteArray);
outStream.close();
} else {
outStream = new FileOutputStream
(String.format(imageFilePath,System.currentTimeMillis()));
outStream.write(data);
outStream.close();
}
preview.camera.startPreview();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
};
看一看-有人能帮我做这件事吗,但是我得到的字节[]仍然给我一张风景照片。Set mCamera.setDisplayOrientation(90);摄像机视图正常,但视频结果与摄像机视图不一样,它不能旋转90度。为什么?嘿,你可以用param.setRotation(..)方法来做这个。我仍在试图弄清楚它是如何工作的。太棒了!
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
mCamera.setDisplayOrientation(90);
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
imageFilePath = getFilename();
InputStream is = new ByteArrayInputStream(data);
Bitmap bmp = BitmapFactory.decodeStream(is);
// Getting width & height of the given image.
if (bmp != null){
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rotatedBMP.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
outStream = new FileOutputStream
(String.format(imageFilePath,System.currentTimeMillis()));
outStream.write(byteArray);
outStream.close();
} else {
outStream = new FileOutputStream
(String.format(imageFilePath,System.currentTimeMillis()));
outStream.write(data);
outStream.close();
}
preview.camera.startPreview();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
};