Code example for Matrix

Methods: mapRect, setRectToRect

     * @param displayBounds  final bounds for crop 
     * @return  the stretched/scaled/translated crop bounds that fit within displayBounds 
    public static RectF getScaledCropBounds(RectF cropBounds, RectF photoBounds,
            RectF displayBounds) {
        Matrix m = new Matrix();
        m.setRectToRect(photoBounds, displayBounds, Matrix.ScaleToFit.FILL);
        RectF trueCrop = new RectF(cropBounds);
        if (!m.mapRect(trueCrop)) {
            return null; 
        return trueCrop;
     * Returns the size of a bitmap in bytes. 
     * @param bmap  bitmap whose size to check 
     * @return  bitmap size in bytes 
    public static int getBitmapSize(Bitmap bmap) {
        return bmap.getRowBytes() * bmap.getHeight();