三星Galaxy S相机意外崩溃

时间:2012-02-21 08:23:44

标签: android camera

我的应用程序崩溃时没有像here那样的堆栈跟踪。我也在使用三星Galaxy S.它可以很好地满足我对HTC的需求。解决方案是“删除预览视图并重新实例化”

但是,我创建的surfaceview以这种方式完成

camera = (SurfaceView) findViewById(R.id.cameraview);

如何解决此问题或如何重新实现此SurfaceView?

02-21 15:57:20.305: ERROR/SecCamera(2357): startPreview: get the first frame of the preview
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): startPreview : return startPreview 0
02-21 15:57:20.305: DEBUG/CameraHardwareSec(2357): MemoryHeapBase(fd(33), size(3686464), width(640), height(480))
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mPostViewWidth = 640 mPostViewHeight = 480 mPostViewSize = 614400
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mRawHeap : MemoryHeapBase(previewHeapSize(614408))
02-21 15:57:20.305: WARN/CameraService(2357): width(640), height(480), format:yuv420sp
02-21 15:57:20.328: ERROR/SecCamera(2357): fimc_v4l2_streamoff()
02-21 15:57:20.336: ERROR/SecCamera(2357): ERR(fimc_v4l2_streamoff):VIDIOC_STREAMOFF failed
02-21 15:57:20.336: ERROR/SecCamera(2357): int android::SecCamera::stopRecord()::1494 fail. errno: No such device
02-21 15:57:20.336: ERROR/CameraHardwareSec(2357): ERR(previewThread):Fail on mSecCamera->stopRecord()
02-21 15:57:20.363: WARN/CameraService(2357): startRecording (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startCameraMode(1) (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startRecordingMode (pid 2357)
02-21 15:57:20.367: DEBUG/SecCamera(2357): passed fmt = 842094164 found pixel format[8]: YUV 4:2:0 planar, Y/CbCr, Tiled
02-21 15:57:20.367: ERROR/SecCamera(2357): startRecord: m_recording_width = 320, m_recording_height = 240

2 个答案:

答案 0 :(得分:0)

我认为设置预览参数应该存在一些问题。 请尝试以下。

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {



if (isPreviewRunning) {
    camera.stopPreview();
}
try{
Camera.Parameters p = camera.getParameters();
if(p!=null){
List<Size> sizes = p.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
p.setPreviewSize(optimalSize.width, optimalSize.height);
camera.setParameters(p);

camera.setPreviewDisplay(holder);;
camera.startPreview();

}
} catch (IOException e) {
    // TODO Auto-generated catch block


    e.printStackTrace();
}

isPreviewRunning = true;
}
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
// TODO Auto-generated method stub
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;

Size optimalSize = null;
double minDiff = Double.MAX_VALUE;

int targetHeight = h;

// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}

// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {



if (isPreviewRunning) {
    camera.stopPreview();
}
try{
Camera.Parameters p = camera.getParameters();
if(p!=null){
List<Size> sizes = p.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
p.setPreviewSize(optimalSize.width, optimalSize.height);
camera.setParameters(p);

camera.setPreviewDisplay(holder);;
camera.startPreview();

}
} catch (IOException e) {
    // TODO Auto-generated catch block


    e.printStackTrace();
}

isPreviewRunning = true;
}

private size getOptimalPreviewSize(List sizes,int w,int h){

// TODO Auto-generated method stub
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;

Size optimalSize = null;
double minDiff = Double.MAX_VALUE;

int targetHeight = h;

// Try to find an size match aspect ratio and size
for (Size size : sizes) {
double ratio = (double) size.width / size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}

// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;

}

将此代码放在surfaceChanged()中。 getOptimalPreviewSize()用于根据设备分辨率设置预览参数。

答案 1 :(得分:0)

好吧,我将固件升级到2.3.3,现在正在运行。