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.13k
    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

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

    // get cropped image in cropped ImageView

    1. 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
Reset Password
Fill out the form below and reset your password: