Ignore:
Timestamp:
2007-03-19T12:21:40+01:00 (18 years ago)
Author:
frsantos
Message:

Keep Yahoo logo in images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/josm/plugins/ywms/src/org/openstreetmap/josm/plugins/ywms/ImageLoader.java

    r2264 r2283  
    5353        private URL yahooUrl;
    5454        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;
    5859        Image image;
    5960        List<String> firefoxFiles = new ArrayList<String>();
     
    128129                {
    129130                        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                }
    135139                    else if( line.startsWith(GECKO_DEBUG_LINE))
    136140                    {
     
    168172                }
    169173
    170                 if( final_bbox == null && imageFilePpm == null && !firefoxFiles.isEmpty() )
     174                if( final_width == -1 && imageFilePpm == null && !firefoxFiles.isEmpty() )
    171175                {
    172176                        throw new ImageLoaderException("Is there any other firefox window open with same profile?");
    173177                }
    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?");
    177181                }
    178182                if( imageFilePpm == null )
     
    221225        private void resizeImage()
    222226        {
    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        
    229227                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");
    236233        }
    237234
     
    265262         * @throws IOException When error saving the file
    266263         */
    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        }
    272276        }
    273277       
Note: See TracChangeset for help on using the changeset viewer.