Ignore:
Timestamp:
2017-10-25T23:26:40+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #15476 - Antialiased text and better resize quality when viewing photos

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

    r12846 r13038  
    1313import java.awt.Point;
    1414import java.awt.Rectangle;
     15import java.awt.RenderingHints;
    1516import java.awt.Toolkit;
    1617import java.awt.event.MouseEvent;
     
    2829import org.openstreetmap.josm.spi.preferences.Config;
    2930import org.openstreetmap.josm.tools.ExifReader;
     31import org.openstreetmap.josm.tools.ImageProvider;
    3032import org.openstreetmap.josm.tools.Logging;
    3133
     
    461463    }
    462464
     465    /**
     466     * Sets the On-Screen-Display text.
     467     * @param text text to display on top of the image
     468     */
    463469    public void setOsdText(String text) {
    464470        this.osdText = text;
     
    478484            visibleRect = this.visibleRect;
    479485            errorLoading = this.errorLoading;
     486        }
     487
     488        if (g instanceof Graphics2D) {
     489            ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    480490        }
    481491
     
    502512        } else {
    503513            Rectangle target = calculateDrawImageRectangle(visibleRect, size);
    504             g.drawImage(image,
    505                     target.x, target.y, target.x + target.width, target.y + target.height,
    506                     visibleRect.x, visibleRect.y, visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height,
    507                     null);
     514            // See https://community.oracle.com/docs/DOC-983611 - The Perils of Image.getScaledInstance()
     515            // Pre-scale image when downscaling by more than two times to avoid aliasing from default algorithm
     516            if (selectedRect == null && (target.width < visibleRect.width/2 || target.height < visibleRect.height/2)) {
     517                BufferedImage buffImage = ImageProvider.toBufferedImage(image);
     518                g.drawImage(ImageProvider.createScaledImage(buffImage, target.width, target.height, RenderingHints.VALUE_INTERPOLATION_BILINEAR),
     519                        target.x, target.y, target.x + target.width, target.y + target.height,
     520                        visibleRect.x, visibleRect.y, visibleRect.x + target.width, visibleRect.y + target.height,
     521                        null);
     522            } else {
     523                g.drawImage(image,
     524                        target.x, target.y, target.x + target.width, target.y + target.height,
     525                        visibleRect.x, visibleRect.y, visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height,
     526                        null);
     527            }
    508528            if (selectedRect != null) {
    509529                Point topLeft = img2compCoord(visibleRect, selectedRect.x, selectedRect.y, size);
Note: See TracChangeset for help on using the changeset viewer.