public Rectangle2D getImageRectangle() {

        if (image == null) {
            return null;
        }

        double componentWidth = this.getWidth();
        double componentHeight = this.getHeight();
        double imageWidth = image.getWidth(this);
        double imageHeight = image.getHeight(this);
        double wImageWidth = imageWidth;
        double wImageHeight = imageHeight;
        double hImageWidth = 0;
        double hImageHeight = 0;
        double newImageWidth = 0;
        double newImageHeight = 0;

        // check if image was loaded successfully
        if ((imageWidth > 0) && (imageHeight > 0)) {

            if (imageWidth == componentWidth && imageHeight == componentHeight) {
                wImageWidth = imageWidth;
                wImageHeight = imageHeight;
            }

            // Scale image to fit the canvas
            // calc new dimensions based on width
            if (imageWidth != componentWidth) {
                wImageWidth = componentWidth;
                wImageHeight = imageHeight * componentWidth / imageWidth;
            }

            // calc new dimensions based on height
            if (imageHeight != componentHeight) {
                hImageHeight = componentHeight;
                hImageWidth = imageWidth * componentHeight / imageHeight;
            }

            // assign one set of new dimensions or the other
            if (wImageHeight > componentHeight) {
                // the new height based on width is too large
                newImageHeight = hImageHeight;
                newImageWidth = hImageWidth;
            }
            else {
                // assume new width based on height is too large
                newImageHeight = wImageHeight;
                newImageWidth = wImageWidth;
            }
        }

        double x = (componentWidth - newImageWidth) / 2.0;
        double y = (componentHeight - newImageHeight) / 2.0;

        return new Rectangle2D.Double(x, y, newImageWidth, newImageHeight);

    }