How to set photo resolution or how to change to hide the entire ImageView

1

I'm using the android camera function I need to change the image resolution to occupy my ImageView completely

used code

public void onClickCamera(View v){

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


public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap)data.getExtras().get("data");
        imageView.setImageBitmap(photo);
        imageView2.setImageBitmap(photo);       
}

Any tips or a better way to use and get the expected result or how instagram does

    
asked by anonymous 25.04.2014 / 21:28

1 answer

1

If it is only to visually decrease the image, you can change the ImageView's ScaleType property to ImageView.ScaleType.CENTER_INSIDE , so ImageView will resize the image proportionally when you draw it:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap)data.getExtras().get("data");
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setImageBitmap(photo);
    }
}

However, this solution ends up consuming a little more processing because the image is resized every time the image needs to be drawn.

If this is a problem, you can use a bit more memory, and create a smaller copy of the bitmap, already with the size of ImageView (by default this operation must be performed on another Thread / Task):

Bitmap reduzido = Bitmap.createScaledBitmap(photo, LARGURA_DESEJADA, ALTURA_DESEJADA, true);
imageView.setImageBitmap(reduzido);

This will save processing, since ImageView does not need to resize the image every time, but spends a little more memory.

    
25.04.2014 / 22:08