我正在使用前置摄像头拍摄照片并在图像视图中显示,但是使用三星星系标签中的前脸摄像头不能拍摄图像。谁能说出问题是什么?即使我已经设定了图片格式。我使用了getoptimalpreview大小来预览大小。如果我错过任何东西,有人可以告诉我吗?预览显示正常,但点击“拍照”背景为黑色
mCamera = Camera.open();
Parameters params = mCamera.getParameters();
params.set("camera-id", 2);
params.setPictureFormat(PixelFormat.JPEG);
在imageview中保存并设置显示
public void onPictureTaken(byte[] data, Camera camera)
{
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
imv.setImageBitmap(bmp);
String filename = "vijaypicture.jpg";
File pictureFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + filename);
try
{
FileOutputStream pfos = new FileOutputStream(pictureFile);
bmp.compress(CompressFormat.JPEG, 75, pfos);
pfos.flush();
pfos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
答案 0 :(得分:2)
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(String.format(
"/sdcard/test/%d.jpg", System.currentTimeMillis()));
outStream.write(data);
outStream.close();
Log.d("", "onPictureTaken - wrote bytes: " + data.length);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
Log.d("", "onPictureTaken - jpeg");
}
希望这有帮助,手动创建文件夹或在代码中使用mkdir命令创建文件夹,并构建一个检查文件是否已存在