Changeset 4698 in josm


Ignore:
Timestamp:
Dec 22, 2011 6:13:15 PM (17 months ago)
Author:
Don-vip
Message:

fix #7165 - Exception is thrown after moving an opened image.

File:
1 edited

Legend:

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

    r4241 r4698  
    8585 
    8686            boolean error = tracker.isErrorID(1); 
    87             if (img.getWidth(null) == 0 || img.getHeight(null) == 0) { 
     87            if (img.getWidth(null) < 0 || img.getHeight(null) < 0) { 
    8888                error = true; 
    8989            } 
     
    9696                } 
    9797 
    98                 ImageDisplay.this.image = img; 
    99                 visibleRect = new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)); 
    100  
    101                 final int w = (int) visibleRect.getWidth(); 
    102                 final int h = (int) visibleRect.getHeight(); 
    103  
    104                 outer: { 
    105                     final int hh, ww, q; 
    106                     final double ax, ay; 
    107                     switch (orientation) { 
    108                     case 8: 
    109                         q = -1; 
    110                         ax = w / 2; 
    111                         ay = w / 2; 
    112                         ww = h; 
    113                         hh = w; 
    114                         break; 
    115                     case 3: 
    116                         q = 2; 
    117                         ax = w / 2; 
    118                         ay = h / 2; 
    119                         ww = w; 
    120                         hh = h; 
    121                         break; 
    122                     case 6: 
    123                         q = 1; 
    124                         ax = h / 2; 
    125                         ay = h / 2; 
    126                         ww = h; 
    127                         hh = w; 
    128                         break; 
    129                     default: 
    130                         break outer; 
     98                if (!error) { 
     99                    ImageDisplay.this.image = img; 
     100                    visibleRect = new Rectangle(0, 0, img.getWidth(null), img.getHeight(null)); 
     101     
     102                    final int w = (int) visibleRect.getWidth(); 
     103                    final int h = (int) visibleRect.getHeight(); 
     104     
     105                    outer: { 
     106                        final int hh, ww, q; 
     107                        final double ax, ay; 
     108                        switch (orientation) { 
     109                        case 8: 
     110                            q = -1; 
     111                            ax = w / 2; 
     112                            ay = w / 2; 
     113                            ww = h; 
     114                            hh = w; 
     115                            break; 
     116                        case 3: 
     117                            q = 2; 
     118                            ax = w / 2; 
     119                            ay = h / 2; 
     120                            ww = w; 
     121                            hh = h; 
     122                            break; 
     123                        case 6: 
     124                            q = 1; 
     125                            ax = h / 2; 
     126                            ay = h / 2; 
     127                            ww = h; 
     128                            hh = w; 
     129                            break; 
     130                        default: 
     131                            break outer; 
     132                        } 
     133     
     134                        final BufferedImage rot = new BufferedImage(ww, hh, BufferedImage.TYPE_INT_RGB); 
     135                        final AffineTransform xform = AffineTransform.getQuadrantRotateInstance(q, ax, ay); 
     136                        final Graphics2D g = rot.createGraphics(); 
     137                        g.drawImage(image, xform, null); 
     138                        g.dispose(); 
     139     
     140                        visibleRect.setSize(ww, hh); 
     141                        image.flush(); 
     142                        ImageDisplay.this.image = rot; 
    131143                    } 
    132  
    133                     final BufferedImage rot = new BufferedImage(ww, hh, BufferedImage.TYPE_INT_RGB); 
    134                     final AffineTransform xform = AffineTransform.getQuadrantRotateInstance(q, ax, ay); 
    135                     final Graphics2D g = rot.createGraphics(); 
    136                     g.drawImage(image, xform, null); 
    137                     g.dispose(); 
    138  
    139                     visibleRect.setSize(ww, hh); 
    140                     image.flush(); 
    141                     ImageDisplay.this.image = rot; 
    142144                } 
    143145 
Note: See TracChangeset for help on using the changeset viewer.