Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Get/Crop the visible portion of ImageView

    • 0
    • 1
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 2.10k
    Comment on it

    In many application we set the scaleType of large image to "CENTER" or the scaleType is set to "MATRIX" and the bitmap is translated and scaled. Therefore parts of the image are not visible. Now in order to get the visible part you just need to enable the drawing cache and grab it from the view.
    // set image in source ImageView and set is scaleType to CENTER

        sourceImageView.setImageBitmap(bitmap);
        sourceImageView.setScaleType(ImageView.ScaleType.CENTER);
        sourceImageView.setDrawingCacheEnabled(true);
    

    // get cropped image in cropped ImageView

    croppedImageView.setImageBitmap(sourceImageView.getDrawingCache());
    

    You can also use to above code by getting or crop the zoomed bitmap when you zoom your Image contained in an ImageView.

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: