저는 카메라를 열고 사진을 찍는 버튼을 클릭하는 프로젝트에서 작업하고 있습니다. imageview.I 파일에 이미지를 저장하고 내 전화의 디렉토리에서 이미지를 열면 큰 크기로 표시됩니다. 이미지 뷰에서 이미지를 더 크게 표시하려면 어떻게해야합니까?이미지가 너비와 높이가 wrap_content인데도 불구하고 안드로이드에서 너무 작게 표시되었습니다.
코드 :
btncamera.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
captureImage();
}
});
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
// start the image capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// if the result is capturing Image
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode ==getActivity().RESULT_OK) {
// successfully captured the image
// display it in image view
//image_uri=data.getData().toString();
previewCapturedImage();
} else if (resultCode == getActivity().RESULT_CANCELED) {
// user cancelled Image capture
image_path=null;
Toast.makeText(getActivity(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
// failed to capture image
Toast.makeText(getActivity(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
}
}
private void previewCapturedImage() {
try {
// bimatp factory
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
final Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
ExifInterface exif = null;
try {
exif = new ExifInterface(fileUri.getPath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String orientString = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
int orientation = orientString != null ? Integer.parseInt(orientString) : ExifInterface.ORIENTATION_NORMAL;
int rotationAngle = 0;
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) rotationAngle = 90;
if (orientation == ExifInterface.ORIENTATION_ROTATE_180) rotationAngle = 180;
if (orientation == ExifInterface.ORIENTATION_ROTATE_270) rotationAngle = 270;
Matrix matrix = new Matrix();
matrix.setRotate(rotationAngle, (float) bitmap.getWidth()/2, (float) bitmap.getHeight()/2);
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, options.outWidth, options.outHeight, matrix, true);
iv_preview.setImageBitmap(rotatedBitmap);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/*
* returning image/video
*/
private File getOutputMediaFile(int type) {
// External sdcard location
File mediaStorageDir = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
IMAGE_DIRECTORY_NAME);
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create "
+ IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
// Create a media file name
// String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
// Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
//change image_path file name required for marina with the name of the file
mediaFile = new File(mediaStorageDir.getPath()+File.separator+user_id+"_"+job_object.job_id+"_"+task_id+".jpg");
// if(mediaFile.exists())
// {
// mediaFile.delete();
// mediaFile = new File(mediaStorageDir.getPath()+File.separator+user_id+"_"+job_object.job_id+"_"+task_id+".jpg");
// }
//IF YOU MAKE CHANGE TO THE FILE NAME PATH ALSO CHANGE IN loadpreviousimage method
image_path=mediaStorageDir.getPath() + File.separator+user_id+"_"+job_object.job_id+"_"+task_id+".jpg";
} else {
return null;
}
return mediaFile;
}
내가 작은 이미지를 얻고 있다고 때문에이 라인 options.inSampleSize = 4;
의 그것입니까?
어떻게 문제를 해결할 수 있습니까?
'options.inSampleSize = 4' 너무 당신의 높은 해상도 이미지를 디코딩하지만 이미지 품질이 좋은하지 않습니다. 그래서'options.inSampleSize = 1'을 사용할 수 있습니다 – Piyush