android位图无法获得最大分辨率

时间:2018-03-01 16:10:10

标签: android android-camera android-bitmap android-gallery android-crop

我目前正在制作一款Android摄影应用。在我的上传片段中,我有相机意图和图库意图,但是当我将图像显示到图像视图时,图像的质量会降低。这是我的代码:

    public void CameraIntent(){
    cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    file = new File(Environment.getExternalStorageDirectory(),
            "file"+String.valueOf(System.currentTimeMillis())+".jpg");
    uri = Uri.fromFile(file);
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT , uri);
    cameraIntent.putExtra("return-data",true);
    startActivityForResult(cameraIntent,0);
}
public void GalleryIntent(){
    galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(galleryIntent,"Select Image from Gallery"),2);
}
    public void cropImage(){
    try{
        CropIntent = new Intent("com.android.camera.action.CROP");
        CropIntent.setDataAndType(uri,"image/*");

        CropIntent.putExtra("crop","true");
        CropIntent.putExtra("outputX",180);
        CropIntent.putExtra("outputY",180);
        CropIntent.putExtra("aspectX",3);
        CropIntent.putExtra("aspectY",3);
        CropIntent.putExtra("scaleUpIfNeeded",true);
        CropIntent.putExtra("return-data",true);

        startActivityForResult(CropIntent,1);
    }
    catch (ActivityNotFoundException ex)
    {
        ex.printStackTrace();
    }
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == 0 && resultCode == RESULT_OK) {
        cropImage();
    }
    else if(requestCode == 2)
    {
        if(data != null)
        {
            uri = data.getData();
            cropImage();
        }
    }
    else if (requestCode == 1 && resultCode == RESULT_OK)
    {
        if(data != null)
        {
            bundle = data.getExtras();
            UriF = data.getData();

            bitmap = (Bitmap)data.getExtras().get("data");
            imageView.setImageBitmap(bitmap);
            seePreview.setEnabled(true);
            submitUpload.setEnabled(true);
            seePreview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    titleS = title.getText().toString();
                    descriptionS = description.getText().toString();
                    openPreview(titleS , descriptionS , bitmap, UriF);
                }
            });
            submitUpload.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    submit(bitmap);
                }
            });
        }
    }

我发现质量严重下降。这是实际的照片: Actual photo

这是我把它放在imageview中时的样子 Photo after putting to the image view

质量发生了重大变化。我尝试使用URI,但是,UriF = data.getdata()返回null。

0 个答案:

没有答案