单击“通过手机摄像头拍摄图像”并将其设置为“原始质量”中

时间:2017-06-03 06:36:26

标签: android listview android-camera

我尝试使用原始质量设置imageview,但图像会被压缩。 请帮我在imageview中设置原始质量的图像。

ImageView imageView;
private static final int CAMERA_REQUEST = 1888;
Bitmap photo;



  uploadImg.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {

           Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
           startActivityForResult(cameraIntent, CAMERA_REQUEST);

       }
   });


  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST) {
        if(data!=null) {
            photo = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(photo);
        }

    }
}

1 个答案:

答案 0 :(得分:1)

尝试使用滑动,首先在你的gradle添加依赖

header h1{
  margin:0;
...
}

使用此代码获取捕获图像

compile 'com.github.bumptech.glide:glide.3.7.0'

然后在values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, "New Picture"); values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera"); imageUri = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); startActivityForResult(intent, PICTURE_RESULT);

onActivityResult

获得图像路径

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {

        case PICTURE_RESULT:
            if (requestCode == PICTURE_RESULT)
                if (resultCode == Activity.RESULT_OK) {
                    try {
                        thumbnail = MediaStore.Images.Media.getBitmap(
                                getContentResolver(), imageUri);
                        imgView.setImageBitmap(thumbnail);
                        imageurl = getRealPathFromURI(imageUri);

    Imageview imageView = (ImageView) findViewById(R.id.image_view); 

 Glide.with(this).load(imageurl).into(imageView); 


                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
        }
    }