There is an ImageMagnifier, which is a magnifying glass for ImageView:
public class ImageMagnifier extends android.support.v7.widget.AppCompatImageView { private PointF zoomPos; private boolean zooming = false; private Matrix matrix; private Paint paint; private Bitmap bitmap; private BitmapShader shader; private int sizeOfMagnifier = 200; public ImageMagnifier(Context context) { super(context); init(); } public ImageMagnifier(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public ImageMagnifier(Context context, AttributeSet attrs) { super(context, attrs); init(); } private void init() { zoomPos = new PointF(0, 0); matrix = new Matrix(); paint = new Paint(); } @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); zoomPos.x = event.getX(); zoomPos.y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: zooming = true; this.invalidate(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: zooming = false; this.invalidate(); break; default: break; } return true; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!zooming) { buildDrawingCache(); } else { bitmap = getDrawingCache(); shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); paint = new Paint(); paint.setShader(shader); matrix.reset(); matrix.postScale(2f, 2f, zoomPos.x, zoomPos.y); paint.getShader().setLocalMatrix(matrix); canvas.drawCircle(zoomPos.x, zoomPos.y - 150, sizeOfMagnifier, paint); } } } Everything works correctly, but I don’t know how to add a frame for a magnifying glass. Tried to do something like:
paint.setStyle(Paint.Style.STROKE); paint.setColor(Color.BLACK); But in this case, an inversion is obtained: the enlarged image is displayed in a frame (which should be black), and the magnifying glass itself is empty.