Ignore:
Timestamp:
2017-11-19T00:10:41+01:00 (2 years ago)
Author:
Don-vip
Message:

see #15476, fix #15511 - fix image scaling regression and makes geoimage feature more configurable through prefs (adjustable max zoom, zoom-step, click zooming with mouse buttons (e.g. if a mouse wheel is not present). Patch by cmuelle8

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r13038 r13127  
    1212import java.awt.Image;
    1313import java.awt.Point;
     14import java.awt.Rectangle;
    1415import java.awt.RenderingHints;
    1516import java.awt.Toolkit;
     
    14211422            if (w > targetWidth) {
    14221423                w /= 2;
    1423                 if (w < targetWidth) {
    1424                     w = targetWidth;
    1425                 }
     1424            }
     1425            if (w < targetWidth) {
     1426                w = targetWidth;
    14261427            }
    14271428            if (h > targetHeight) {
    14281429                h /= 2;
    1429                 if (h < targetHeight) {
    1430                     h = targetHeight;
    1431                 }
     1430            }
     1431            if (h < targetHeight) {
     1432                h = targetHeight;
    14321433            }
    14331434            BufferedImage tmp = new BufferedImage(w, h, type);
     
    19761977        }
    19771978    }
     1979
     1980    /**
     1981     * Converts an {@link Rectangle} area of {@link Image} to a {@link BufferedImage} instance.
     1982     * @param image image to convert
     1983     * @param crop_area rectangle to crop image with
     1984     * @return a {@code BufferedImage} instance for the cropped area of {@code Image}.
     1985     * @since 13127
     1986     */
     1987    public static BufferedImage toBufferedImage(Image image, Rectangle crop_area) {
     1988        BufferedImage buffImage = null;
     1989
     1990        Rectangle r = new Rectangle(image.getWidth(null), image.getHeight(null));
     1991        if (r.intersection(crop_area).equals(crop_area)) {
     1992            buffImage = new BufferedImage(crop_area.width, crop_area.height, BufferedImage.TYPE_INT_ARGB);
     1993            Graphics2D g2 = buffImage.createGraphics();
     1994            g2.drawImage(image,
     1995                0, 0, crop_area.width, crop_area.height,
     1996                crop_area.x, crop_area.y,
     1997                crop_area.x + crop_area.width, crop_area.y + crop_area.height,
     1998                null);
     1999            g2.dispose();
     2000        }
     2001        return buffImage;
     2002    }
    19782003}
Note: See TracChangeset for help on using the changeset viewer.