Changeset 18109 in osm for applications/editors/josm
- Timestamp:
- 2009-10-13T12:22:54+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java
r17089 r18109 5 5 import java.awt.event.ActionEvent; 6 6 import java.awt.image.BufferedImage; 7 import java.io.BufferedOutputStream; 7 8 import java.io.File; 9 import java.io.FileOutputStream; 8 10 import java.io.IOException; 9 11 10 12 import javax.imageio.ImageIO; 11 13 import javax.swing.JFileChooser; 14 import javax.swing.filechooser.FileFilter; 12 15 13 16 import org.openstreetmap.josm.Main; 14 17 import org.openstreetmap.josm.actions.JosmAction; 18 19 import com.sun.image.codec.jpeg.JPEGCodec; 20 import com.sun.image.codec.jpeg.JPEGImageEncoder; 15 21 16 22 public class MenuActionSaveRasterAs extends JosmAction { … … 21 27 22 28 private WMSLayer wmsLayer; 29 30 public class FiltrePng extends FileFilter { 31 @Override 32 public boolean accept(File file) { 33 if (file.isDirectory()) { 34 return true; 35 } 36 return file.getName().toLowerCase().endsWith(".png"); 37 } 38 39 @Override 40 public String getDescription() { 41 return tr("PNG files (*.png)"); 42 } 43 44 } 45 46 FiltrePng filtrePng = new FiltrePng(); 23 47 24 48 public MenuActionSaveRasterAs(WMSLayer wmsLayer) { … … 30 54 File file; 31 55 JFileChooser fc = new JFileChooser(); 56 fc.setFileFilter(filtrePng); 32 57 int returnVal = fc.showSaveDialog(Main.parent); 33 58 if (returnVal == JFileChooser.APPROVE_OPTION) { 34 59 file = fc.getSelectedFile(); 60 if (!file.getName().endsWith(".png")) 61 file = new File(file.getParent(), file.getName()+".png"); 35 62 BufferedImage bi = wmsLayer.images.get(0).image; 36 63 try { 37 64 ImageIO.write(bi, "png", file); 65 /* 66 FileOutputStream flux = new FileOutputStream(file); 67 BufferedOutputStream fluxBuf = new BufferedOutputStream(flux); 68 JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bi)); 69 codec.encode(bi); 70 fluxBuf.close(); 71 */ 38 72 } catch (IOException e) { 39 73 e.printStackTrace();
Note:
See TracChangeset
for help on using the changeset viewer.