- Timestamp:
- 2020-11-26T22:24:24+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/BufferedImageCacheEntry.java
r11331 r17363 4 4 import java.awt.image.BufferedImage; 5 5 import java.io.ByteArrayInputStream; 6 import java.io.ByteArrayOutputStream; 6 7 import java.io.IOException; 8 import java.io.UncheckedIOException; 7 9 8 10 import javax.imageio.ImageIO; … … 28 30 public BufferedImageCacheEntry(byte[] content) { 29 31 super(content); 32 } 33 34 /** 35 * Encodes the given image as PNG and returns a cache entry 36 * @param img the image 37 * @return a cache entry for the PNG encoded image 38 * @throws UncheckedIOException if an I/O error occurs 39 */ 40 public static BufferedImageCacheEntry pngEncoded(BufferedImage img) { 41 try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { 42 ImageIO.write(img, "png", output); 43 return new BufferedImageCacheEntry(output.toByteArray()); 44 } catch (IOException e) { 45 throw new UncheckedIOException(e); 46 } 30 47 } 31 48 -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ThumbsLoader.java
r16398 r17363 9 9 import java.awt.geom.AffineTransform; 10 10 import java.awt.image.BufferedImage; 11 import java.io.ByteArrayOutputStream;12 11 import java.io.File; 13 12 import java.io.IOException; 13 import java.io.UncheckedIOException; 14 14 import java.util.ArrayList; 15 15 import java.util.Collection; 16 17 import javax.imageio.ImageIO;18 16 19 17 import org.apache.commons.jcs3.access.behavior.ICacheAccess; … … 165 163 166 164 if (!cacheOff && cache != null) { 167 try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { 168 ImageIO.write(scaledBI, "png", output); 169 cache.put(cacheIdent, new BufferedImageCacheEntry(output.toByteArray())); 170 } catch (IOException e) { 165 try { 166 cache.put(cacheIdent, BufferedImageCacheEntry.pngEncoded(scaledBI)); 167 } catch (UncheckedIOException e) { 171 168 Logging.warn("Failed to save geoimage thumb to cache"); 172 169 Logging.warn(e);
Note:
See TracChangeset
for help on using the changeset viewer.