gpt4 book ai didi

android - Samsung galaxy S4 图像捕捉问题

转载 作者:太空狗 更新时间:2023-10-29 15:10:47 27 4
gpt4 key购买 nike

enter image description here我正在开发一个 Android 应用程序。我创建了一个自定义相机类来捕捉图像。它在许多设备上运行良好,但当我尝试使用 Samsung Galaxy S4 时,它返回带有灰色线条的图像,如图所示。我的代码是:

![`*public void surfaceCreated(SurfaceHolder holder) {
frontCam = SharedUserPrefs.getSharedPrefData(AutoCapture.this,
Constants.IS_FRONT_CAMERA);

if (frontCam.equals(Constants.VALUE_ON)) {

for (int camIdx = 0; camIdx < Camera.getNumberOfCameras(); camIdx++) {
Camera.getCameraInfo(camIdx, cameraInfo);
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
try {
mCamera = Camera.open(camIdx);
} catch (RuntimeException e) {
Log.e(TAG,
"Camera failed to open: "
+ e.getLocalizedMessage());
}
}
}

} else {
mCamera = Camera.open();
}
mCamera.setDisplayOrientation(90);
Camera.Parameters p = mCamera.getParameters();
if (getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA_FLASH)) {
if (flashOn.equals(Constants.VALUE_ON)) {
{
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
}
} else {
p.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
}
p.setPictureFormat(ImageFormat.JPEG);

List<Camera.Size> previewSizes = p.getSupportedPreviewSizes();
Camera.Size previewsize = previewSizes.get(0);
for (Camera.Size size : previewSizes) {
Log.d("Width---" + size.width, "Height---" + size.height);
}

p.setPreviewSize(previewsize.width, previewsize.height);

mCamera.setParameters(p);

}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Log.e(TAG, "surfaceChanged");

if (mPreviewRunning) {
mCamera.stopPreview();
}

try {
mCamera.setPreviewDisplay(holder);

} catch (IOException e) {

System.out.println("Caught exception in surface chagned");
e.printStackTrace();
}
mCamera.startPreview();
mPreviewRunning = true;

}

public void surfaceDestroyed(SurfaceHolder holder) {
Log.e(TAG, "surfaceDestroyed");

if (mPreviewRunning == false) {
if (mCamera != null) {
mPreviewRunning = false;
mCamera.stopPreview();
mCamera.release();
}
if (mCamera != null) {
mPreviewRunning = false;
mCamera.release();
}
}/*
* else if (mCamera != null) { mPreviewRunning = false;
* mCamera.stopPreview(); mCamera.release(); }
*/

}*`][2]

最佳答案

我认为您遇到了我和另一个人遇到的同样问题。

Samsung Galaxy S4 , Image gets corrupted while taking from camera

关于android - Samsung galaxy S4 图像捕捉问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16732123/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com