我在相機中遇到了問題,圖像模糊。Android中的相機捕捉圖像不清晰(模糊)
我搜索了很多,但我不能得到解決
我不知道如何解決問題
這裏是我的代碼,我用攝像機捕獲圖像
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == SELECT_FILE)
onSelectFromGalleryResult(data);
else if (requestCode == REQUEST_CAMERA)
onCaptureImageResult(data);
}
}
private void onCaptureImageResult(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 0, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
img1.setImageBitmap(thumbnail);
}
@SuppressWarnings("deprecation")
private void onSelectFromGalleryResult(Intent data) {
Uri selectedImageUri = data.getData();
String[] projection = {MediaStore.MediaColumns.DATA};
Cursor cursor = managedQuery(selectedImageUri, projection, null, null,
null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
String selectedImagePath = cursor.getString(column_index);
Bitmap bm;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, options);
final int REQUIRED_SIZE = 200;
int scale = 1;
while (options.outWidth/scale/2 >= REQUIRED_SIZE
&& options.outHeight/scale/2 >= REQUIRED_SIZE)
scale *= 2;
options.inSampleSize = scale;
options.inJustDecodeBounds = false;
bm = BitmapFactory.decodeFile(selectedImagePath, options);
img1.setImageBitmap(bm);
}
圖像集圖像集在Imageview中良好,但它僅在攝像頭拍攝時發生Imageview Camera Capture Image is not clear(Blurry) in Android
幫助我t他的問題。
在此先感謝
我有兩個選項圖庫或相機SO我如何修改它。幫我到Modifi這。@ dex –
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,REQUEST_CAMERA);我用這個Open Camera @dex –
@RushangPrajapati:一旦你點擊相機按鈕,調用startCamera活動代碼,一旦點擊結束,然後在OnActivityResult中,你可以得到相應的圖像...過程。對於圖庫,您可以通過Intent調用圖庫intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(「image/*」); startActivityForResult(intent,Gallery_code),然後在onActivityResult中,您將從該uri獲取URI,openInputStream以獲取圖像的位圖。 – dex