相机预览颠倒
Camera Preview upside down
Front Camera is displaying upside down. I am reading each frame. I think i know where to put the code.In surfaceChanged but don't know how to do.
@Override
public void surfaceChanged(SurfaceHolder mHolder, int arg1 , int arg2 , int arg3)
{
if (mHolder.getSurface() == null) { return; }
mCamera.setPreviewCallback(previewCallback);
try
{
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
return;
}
catch (Exception exception)
{
Log.d("CameraView", (new StringBuilder()).append("Error starting camera preview: ")
.append(exception.getMessage()).toString());
}
}
我尝试了什么。
private android.hardware.Camera.PreviewCallback previewCallback = new android.hardware.Camera.PreviewCallback()
{
public void onPreviewFrame(byte abyte0[] , Camera camera)
{
int[] rgbData = YuvUtils.decodeGreyscale(abyte0, widthPreview,heightPreview);
editedBitmap.setPixels(rgbData, 0, widthPreview, 0, 0, widthPreview, heightPreview);
if(MainActivity2.cameraId==CameraInfo.CAMERA_FACING_FRONT) // it is rotating my CameraPreview continuosly.
{
matrix.postRotate(270F);
}
finalBitmap = Bitmap.createBitmap(editedBitmap, 0, 0, widthPreview, heightPreview, matrix, true);
if(saveCurrentFrame)
{
saveCurrentFrame =false;
new BitmapSaver(ctx, finalBitmap).start();
}
}
};
但它不断旋转我的相机预览。我的 Activity 设置为 Potrait 。 我的 Activity
中不允许更改方向
我会用 matrix.setRotate()
.
matrix.postRotate()
每次调用时都会添加旋转。角度从 270 -> 540 -> 810 -> 1080 -> 1350 -> 等等
matrix.setRotate()
总是将其设置为 270。
您可以在拍照前使用 _camera.SetDisplayOrientation(90)
旋转相机预览。
Front Camera is displaying upside down. I am reading each frame. I think i know where to put the code.In surfaceChanged but don't know how to do.
@Override
public void surfaceChanged(SurfaceHolder mHolder, int arg1 , int arg2 , int arg3)
{
if (mHolder.getSurface() == null) { return; }
mCamera.setPreviewCallback(previewCallback);
try
{
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
return;
}
catch (Exception exception)
{
Log.d("CameraView", (new StringBuilder()).append("Error starting camera preview: ")
.append(exception.getMessage()).toString());
}
}
我尝试了什么。
private android.hardware.Camera.PreviewCallback previewCallback = new android.hardware.Camera.PreviewCallback()
{
public void onPreviewFrame(byte abyte0[] , Camera camera)
{
int[] rgbData = YuvUtils.decodeGreyscale(abyte0, widthPreview,heightPreview);
editedBitmap.setPixels(rgbData, 0, widthPreview, 0, 0, widthPreview, heightPreview);
if(MainActivity2.cameraId==CameraInfo.CAMERA_FACING_FRONT) // it is rotating my CameraPreview continuosly.
{
matrix.postRotate(270F);
}
finalBitmap = Bitmap.createBitmap(editedBitmap, 0, 0, widthPreview, heightPreview, matrix, true);
if(saveCurrentFrame)
{
saveCurrentFrame =false;
new BitmapSaver(ctx, finalBitmap).start();
}
}
};
但它不断旋转我的相机预览。我的 Activity 设置为 Potrait 。 我的 Activity
中不允许更改方向我会用 matrix.setRotate()
.
matrix.postRotate()
每次调用时都会添加旋转。角度从 270 -> 540 -> 810 -> 1080 -> 1350 -> 等等
matrix.setRotate()
总是将其设置为 270。
您可以在拍照前使用 _camera.SetDisplayOrientation(90)
旋转相机预览。