保存图像文件是越来越融为一体pressed在android系统 [英] Saving the image to file is getting compressed in android

查看:204
本文介绍了保存图像文件是越来越融为一体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?

这篇关于保存图像文件是越来越融为一体pressed在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆