我是 Android 编程新手。我在安卓手机上做了一个项目。它适用于我的 HTC 渴望 a8181。因为我希望我的软件运行得更快,所以我得到了一个 htc one 。然后程序无法从相机获取帧。以前有人遇到过这样的问题吗?请帮我。(我使用 onPreviewFrame 在我的软件中获取框架。)
public class CopyOfCameraPreview extends SurfaceView implements
SurfaceHolder.Callback, PreviewCallback {
private SurfaceHolder mHolder;
private Camera mCamera;
private boolean preview = false;
public static int w, h, l;
public CopyOfCameraPreview1(Context context) {
super(context);
mCamera = getCameraInstance();
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (mHolder.getSurface() == null) {
return;
}
try {
mCamera.stopPreview();
preview = false;
} catch (Exception e) {
}
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
preview = false;
} catch (Exception e) {
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}
public void surfaceCreated(SurfaceHolder holder) {
try {
mCamera.setPreviewDisplay(holder);
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(960, 544);
parameters.setPreviewFormat(PixelFormat.YCbCr_420_SP);
mCamera.setParameters(parameters);
mCamera.setPreviewCallback(this);
mCamera.startPreview();
preview = true;
} catch (IOException e) {
Log.d(TAG, "Error setting camera preview: " + e.getMessage());
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
if (mCamera != null) {
if (preview) {
mCamera.stopPreview();
preview = false;
}
mCamera.release();
mCamera = null;
}
}
public static Camera getCameraInstance() {
Camera c = null;
try {
c = Camera.open();
} catch (Exception e) {
}
return c;
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
camera.setPreviewCallback(null);
if (data != null) {
Camera.Parameters parameters = mCamera.getParameters();
int imageFormat = parameters.getPreviewFormat();
if (imageFormat == ImageFormat.NV21) {
// Bitmap image = null;
w = parameters.getPreviewSize().width;
h = parameters.getPreviewSize().height;
l = data.length;
decodeYUV420SP(data, w, h);
}
}
camera.setPreviewCallback(this);
}
}
06-22 17:41:51.159: I/QCameraHWI(191): setPreviewWindow : X, mPreviewState = 0
06-22 17:41:51.159: I/CameraService(191): Destroying camera 0
06-22 17:41:51.159: I/QualcommCamera(191): Qint android::close_camera_device(hw_device_t*): device =0x14e1270 E
06-22 17:41:51.159: I/QCameraHWI(191): ~QCameraHardwareInterface: E
06-22 17:41:51.169: I/drawView(16359): Drwaed
06-22 17:41:51.169: E/mm_camera_poll_thread(191): mm_camera_poll_thread_release: err, poll thread of channel 0s not running. cam_id=0
06-22 17:41:51.169: E/mm_camera_poll_thread(191): mm_camera_poll_thread_release: err, poll thread of channel 1s not running. cam_id=0
06-22 17:41:51.169: E/mm_camera_poll_thread(191): mm_camera_poll_thread_release: err, poll thread of channel 2s not running. cam_id=0
06-22 17:41:51.169: E/mm_camera_poll_thread(191): mm_camera_poll_thread_release: err, poll thread of channel 3s not running. cam_id=0
06-22 17:41:51.169: E/mm-camera(206): config_shutdown_pp Camera not in streaming mode. Returning.
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_read_pipe Got EXIT
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: E
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 0 num 0 count = 0 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 1 num -1 count = -1 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 2 num 0 count = 0 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 3 num 0 count = 0 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 4 num 0 count = 0 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: Check for image mode 5 num 0 count = 0 data = 0x0
06-22 17:41:51.169: E/mm-camera(206): mctl_pp_clear_buf: X