06-01 07:48:47.956: W/Camera(6961): Camera server died!
06-01 07:48:47.956: W/Camera(6961): ICamera died
06-01 07:48:47.956: E/Camera(6961): Error 100
我正在调用一个类来捕获图像,然后处理该图像(将其压缩为 640*480),然后将其与其他一些数据(如 lat、lng、md_code、...)一起发送到服务器。
在 Galaxy Note II 上一切正常,但是当我尝试使用小型设备的前置摄像头(Galaxy S Advance)进行测试时,显示此错误。是设备问题
我的代码如下
从活动中调用
// checking a camera?
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA))
{
Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG).show();
}
else
{
cameraId = findFrontFacingCamera();
if (cameraId < 0)
{
Toast.makeText(this, "Sorry you don't have secondary camera",Toast.LENGTH_LONG).show();
//Exit from application
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
camera = Camera.open(cameraId);
}
}
private int findFrontFacingCamera()
{
int cameraId = -1;
// Search for the front facing camera
int numberOfCameras = Camera.getNumberOfCameras();
for (int i = 0; i < numberOfCameras; i++)
{
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (info.facing == CameraInfo.CAMERA_FACING_FRONT)
{
Log.d(DEBUG_TAG, "Front Facing Camera found");
cameraId = i;
break;
}
}
return cameraId;
}
//Calling camara to capture
camera.takePicture(null, null,new PhotoHandler(getApplicationContext(), code, pwd, InOutAb, serverPort));
PhotoHandler 类
public class PhotoHandler implements PictureCallback {
private final Context context;
String mdCode,pass,state,serverPortAddress;
public PhotoHandler(Context context, String code, String pwd,String InOutAb,String serverPort) {
this.context = context;
mdCode = code;
pass = pwd;
state = InOutAb;
serverPortAddress = serverPort;
}
@Override
public void onPictureTaken(byte[] imgData, Camera camera) {
//Compressing the image 640*480
//-----------------------------------------
Bitmap bmp=BitmapFactory.decodeByteArray(imgData, 0, imgData.length);
Bitmap resizedBmp = Bitmap.createScaledBitmap(bmp, 640, 480, false);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
resizedBmp.compress(CompressFormat.PNG, 0, bos);
byte[] data = bos.toByteArray();
//-----------------------------------------
File pictureFileDir = getDir();
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
Toast.makeText(context, "Can't create directory to save image.",Toast.LENGTH_LONG).show();
return;
}
String photoFile = "MyPicture.jpg";
String filename = pictureFileDir.getPath() + File.separator + photoFile;
File pictureFile = new File(filename);
try
{
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
Toast.makeText(context, "New Image saved:" + filename,Toast.LENGTH_LONG).show();
}
catch (Exception error)
{
Log.d("Exception", error+"");
Toast.makeText(context, "Image could not be saved.",Toast.LENGTH_LONG).show();
}
}
private File getDir()
{
File sdDir = Environment.getExternalStorageDirectory();
return new File(sdDir, "Attendance Image");
}
}
**Not even single success toast is given only showing this error**