0

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

    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);
                }
            });
        }
    }

我观察到质量明显下降。这是实际照片: 实际照片

这是我将其放入图像视图后将其放入图像视图时的样子

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

4

0 回答 0