保存图像文件是越来越融为一体pressed在android系统
我是新来android.I必须具有的功能,从画廊上传图片或从相机拍摄图像的应用程序。下面,我已经写了code,其中我得到的图像。
I am new to android.I have an application which has functionality to upload image from the gallery or take image from camera. Below I have written the code where I get the image.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode!=0){
if(PICK_MEDIA_FROM_GALLERY == requestCode){
if(null != data){
Uri uri = data.getData();
//String type = getMimeType(uri);
filePath = getRealPathFromURI(uri);
checkFileSupport(filePath);
}
}else{
if(ACTION_TAKE_PHOTO == requestCode){
checkFileSupport(filePath);
}else if(ACTION_TAKE_VIDEO == requestCode){
handleCameraVideo();
}
}
}
}
此功能是用来固定的形象写的方向。
This function is used to fix the write orientation for the image.
public Bitmap fixOrientation(Bitmap bmp) {
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
if (orientation==6)
{
Matrix matrix = new Matrix();
matrix.postRotate(90);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
else if (orientation==8)
{
Matrix matrix = new Matrix();
matrix.postRotate(270);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
else if (orientation==3)
{
Matrix matrix = new Matrix();
matrix.postRotate(180);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bmp;
}
我使用的功能设置图像到的ImageView
I set Image to imageview using the function
private void setImagePreview(final String realPath) throws IOException {
Display display = getWindowManager().getDefaultDisplay();
Bitmap bitmap = ImageUtils.getThumbnailBitmap(realPath, display.getWidth());
if(null!=bitmap){
//rotate image and save in the same filepath
bitmap = fixOrientation(bitmap);
FileOutputStream fOut = new FileOutputStream(filePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
RelativeLayout tempLayout = (RelativeLayout) findViewById(R.id.previewLayout);
tempLayout.setVisibility(View.VISIBLE);
ImageView previewImageView = (ImageView) findViewById(R.id.previewImageView);
previewImageView.setImageBitmap(bitmap);
}
}
我有一个图像摄像头。
I have the an image in Camera.
当我从图库中选择该图像,第一次,
When I select that image from Gallery for the first time,
当我尝试更改附件,然后选择视图出现这样的画面一样
When I try Changing the attachment and select the same picture the view appears like this
我怎样才能解决这个问题呢?任何人都可以请帮我吗?
How can I solve this issue?Can anyone please help me out?
您第二图像质量似乎比第一次更糟糕。您可以检查是否设置ImageView的宽度和高度 WRAP_CONTENT
?如果是的话,尝试设置为测试一个固定值。是否这两个位图的大小相同,宽度和高度?
Your second image quality seems worse than the first one. You can check whether you set ImageView width and height wrap_content
? If yes, try to set a fixed value for test. and whether the two bitmap sizes are same, width and height?