所以我创建了适用于相机意图的相机应用程序,但由于某些原因,某些手机在拍摄时无法显示图片。后来我发现它主要不适用于高于8mpx的相机。这是我的代码捕获图像:
Intent cameraIntent = newIntent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File output = new File(dir,"pic.png");
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
path = output.getAbsolutePath();
startActivityForResult(cameraIntent, REQUEST_CODE_PHOTO);
并显示它们:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_PHOTO) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
int targetW = width;
int targetH = height;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(path, bmOptions);
iv.setImageBitmap(bitmap);
}
问题是它不适用于超过8mpx的照相手机,如LG g2和三星音符3,但出于某种原因可以使用我的zenfone 2 ze551ml。所以我不知道是什么导致这个问题也许任何人都有这方面的经验。提前谢谢。