Android Camera Preview 无法在 Google Glass 上正确显示?
Posted
技术标签:
【中文标题】Android Camera Preview 无法在 Google Glass 上正确显示?【英文标题】:Android Camera Preview not showing properly on google glass? 【发布时间】:2014-05-15 01:32:28 【问题描述】:我正在开发一个相机应用程序,但问题是我正在制作的相机显示的预览失真。
拍出来的照片很清晰,但是预览就乱了。
下面是完整的相机预览代码,以防万一:
import java.io.IOException;
import java.util.List;
import com.glass.cuxtomcam.constants.CuxtomIntent.CAMERA_MODE;
import android.content.Context;
import android.content.res.Configuration;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.OnZoomChangeListener;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.view.OrientationEventListener;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
public class CameraPreview extends SurfaceView implements
SurfaceHolder.Callback, OnZoomChangeListener
private SurfaceHolder mHolder;
private Camera mCamera;
private Context mContext;
private static String TAG = "CAMERA PREVIEW";
private int zoomOffset;
private CameraListener mCallback;
private int cameraMode;
public CameraPreview(Context context, Camera camera, int cameraMode)
super(context);
mContext = context;
mCamera = camera;
mHolder = getHolder();
this.cameraMode = cameraMode;
mHolder.addCallback(this);
mHolder.setKeepScreenOn(true);
public void setCameraListener(CameraListener listener)
mCallback = listener;
@Override
public synchronized void surfaceChanged(SurfaceHolder holder, int format,
int width, int height)
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null)
// preview surface does not exist
return;
@Override
public void surfaceCreated(SurfaceHolder holder)
if (mCamera != null)
try
mCamera.stopPreview();
if (mCamera.getParameters().isZoomSupported())
mCamera.setZoomChangeListener(this);
zoomOffset = mCamera.getParameters().getMaxZoom() / 5;
mCamera.setPreviewDisplay(holder);
mCamera.startPreview();
mCamera.lock();
catch (IOException e)
Log.e("Error starting preview", e.getMessage());
@Override
public void surfaceDestroyed(SurfaceHolder holder)
if (mCamera != null)
mCamera.stopPreview();
// release the camera
mCamera.release();
// unbind the camera from this object
mCamera = null;
public synchronized void zoomIn()
if (mCamera != null && mCamera.getParameters().isZoomSupported()
&& mCamera.getParameters().isSmoothZoomSupported())
int zoomvalue = mCamera.getParameters().getZoom() + zoomOffset;
if (zoomvalue <= mCamera.getParameters().getMaxZoom())
mCamera.startSmoothZoom(zoomvalue);
else
Toast.makeText(mContext, "Zoom In is not supported",
Toast.LENGTH_LONG).show();
public synchronized void zoomOut()
if (mCamera != null && mCamera.getParameters().isZoomSupported()
&& mCamera.getParameters().isSmoothZoomSupported())
int zoomvalue = mCamera.getParameters().getZoom() - zoomOffset;
if (zoomvalue >= 0)
mCamera.startSmoothZoom(zoomvalue);
else
Toast.makeText(mContext, "Zoom Out is not supported",
Toast.LENGTH_LONG).show();
@Override
public void onZoomChange(int zoomValue, boolean stopped, Camera camera)
// Log.i("Camera Zoom Value", zoomValue + "");
谁能指导我为什么会发生这种情况?
【问题讨论】:
预览设置的分辨率是多少? 【参考方案1】:不确定它是否仍然相关(2 个月后没有答案)。但这是我的相机像你展示的那样时使用的解决方案。
Camera.Parameters parameters = camera.getParameters();
parameters.setPreviewFpsRange(30000, 30000);
parameters.setPreviewSize(640,360);
camera.setParameters(parameters);
它将每秒帧数设置为 30fps,您遇到的问题是帧率过高(很可能)
【讨论】:
在顶部添加断点以查看 camera.getParameters(); 中的信息。您可以将参数设置为该枚举中的任何内容。我建议将帧速率和预览大小调低一点(无论如何你都不会在小屏幕上注意到它,它会让你的 Glass 运行得不那么热/更久)。以上是关于Android Camera Preview 无法在 Google Glass 上正确显示?的主要内容,如果未能解决你的问题,请参考以下文章
android6.0源码分析之Camera API2.0下的Preview(预览)流程分析
android6.0源码分析之Camera API2.0下的Preview(预览)流程分析
是否可以像 Vertex Shader 和 Fragment Shader 一样为 Android Camera Preview 提供效果,并使用 OpenGLES 保存捕获的图像?