Android Studio: Create an image by trimming another saved

0

Good morning. I have a photo taken by the camera. Next I want a series of photos to be loaded in a RecyclerView. This RecyclerView is a list of CardViews. All this is implemented and working.

The problem is that when you load each photo in the CardView, which I have resized to fit in an ImageView, they are distorted, which is logical because the dimensions do not match.

So, what I want is to create a new Bitmap by trimming the image taken by the camera and stored in memory. I can recover the path since I have it saved in a bd. The photos taken are always the same size, so it is not necessary to open an Intent to choose the cut, but I want to capture the upper half of the image.

This method is what resizes the photo captured by the camera.

public Bitmap redimensionarImagen(Bitmap img){

    //se toma como referencia para las nuevas medidas el tamaño en píxeles de la pantalla del terminal

    int newWidth = (context.getResources().getDisplayMetrics().widthPixels*4)/5;
    int newHeight = context.getResources().getDisplayMetrics().heightPixels/4;

    Bitmap resizedBitmap=Bitmap.createScaledBitmap(img, newWidth, newHeight, false);


        return resizedBitmap;
    }

Well, what I want to do is capture a cut of the Bitmap img that is the upper half of the image, and then apply the createScaledBitmap to that new clipping.

    
asked by Alberto Sáez Vela 08.10.2017 в 20:14
source

0 answers