2012-02-21 83 views
0

我的应用程序崩溃没有堆栈跟踪像问什么here。我也使用三星Galaxy S.它与我的HTC愿望很好。该解决方案是“去掉预览视图,并重新将其实例化”三星Galaxy S相机意外崩溃

但是,我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 

回答

0

那么,我升级固件到2.3.3,它现在工作。

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; 
} 

私人尺寸getOptimalPreviewSize(名单大小,INT W,INT 1H){

// 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()用于根据设备分辨率设置预览参数。