Changeset 2283 in osm for utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms
- Timestamp:
- 2007-03-19T12:21:40+01:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java
r2264 r2283 53 53 private URL yahooUrl; 54 54 double[] orig_bbox = null; 55 double[] final_bbox = null; 56 int width = -1; 57 int height = -1; 55 int width = -1; 56 int height = -1; 57 int final_width = -1; 58 int final_height = -1; 58 59 Image image; 59 60 List<String> firefoxFiles = new ArrayList<String>(); … … 128 129 { 129 130 System.out.println("YWMS::" + line); 130 if( line.startsWith("bbox=") ) 131 { 132 final_bbox = getBbox(line); 133 // System.out.println("YWMS::BBOX: (" + final_bbox[0] + "," + final_bbox[1] + "), (" + final_bbox[2] + "," + final_bbox[3] + ")"); 134 } 131 if( line.startsWith("new_width=") ) 132 { 133 final_width = (int)Math.round( Double.parseDouble( line.substring(10)) ); 134 } 135 else if( line.startsWith("new_height=") ) 136 { 137 final_height = (int)Math.round( Double.parseDouble( line.substring(11)) ); 138 } 135 139 else if( line.startsWith(GECKO_DEBUG_LINE)) 136 140 { … … 168 172 } 169 173 170 if( final_ bbox == null&& imageFilePpm == null && !firefoxFiles.isEmpty() )174 if( final_width == -1 && imageFilePpm == null && !firefoxFiles.isEmpty() ) 171 175 { 172 176 throw new ImageLoaderException("Is there any other firefox window open with same profile?"); 173 177 } 174 if( final_ bbox == null)175 { 176 throw new ImageLoaderException("Couldn't find bounding box. Is browser.dom.window.dump.enabled set in Firefox config?");178 if( final_width == -1) 179 { 180 throw new ImageLoaderException("Couldn't find new dimension. Is browser.dom.window.dump.enabled set in Firefox config?"); 177 181 } 178 182 if( imageFilePpm == null ) … … 221 225 private void resizeImage() 222 226 { 223 int calcwidth = (int)Math.round((final_bbox[2] - final_bbox[0]) * width / (orig_bbox[2] - orig_bbox[0]));224 int calcheight = (int)Math.round((final_bbox[3] - final_bbox[1]) * height / (orig_bbox[3] - orig_bbox[1]));225 226 int cropWidth = (calcwidth - width) / 2;227 int cropHeight = (calcheight - height) / 2;228 229 227 Toolkit tk = Toolkit.getDefaultToolkit(); 230 // save("/tmp/image_orig.jpg"); 231 image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, width, height))); 232 image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(calcwidth, calcheight))); 233 image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(cropWidth, cropHeight, width, height))); 234 // BufferedImage img = (BufferedImage)image.getScaledInstance(calcwidth, calcwidth, BufferedImage.SCALE_DEFAULT); 235 // image = img.getSubimage(cropl, cropt, width, height); 228 //save("/tmp/image_orig.png"); 229 image = tk.createImage (new FilteredImageSource (image.getSource(), new CropImageFilter(0, 0, final_width, final_height))); 230 //save("/tmp/image_crop.png"); 231 image = tk.createImage (new FilteredImageSource (image.getSource(), new ReplicateScaleFilter(width, height))); 232 //save("/tmp/image_scale.png"); 236 233 } 237 234 … … 265 262 * @throws IOException When error saving the file 266 263 */ 267 public void save(String fileName) throws IOException 268 { 269 FileOutputStream fileStream = new FileOutputStream(fileName); 270 ImageIO.write(getBufferedImage(), "png", fileStream); 271 fileStream.close(); 264 public void save(String fileName) 265 { 266 try 267 { 268 FileOutputStream fileStream = new FileOutputStream(fileName); 269 ImageIO.write(getBufferedImage(), "png", fileStream); 270 fileStream.close(); 271 } 272 catch(Exception e) 273 { 274 e.printStackTrace(); 275 } 272 276 } 273 277
Note:
See TracChangeset
for help on using the changeset viewer.