Revision 68

View differences:

trunk/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
495 495
    protected BufferedImage copyForcingImageSize(
496 496
        BufferedImage disp_img, int w, int h) {
497 497
        
498
        if (disp_img == null || w < 1 || h < 1) {
499
            return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
500
        }
501
        int from_w = disp_img.getWidth(null);
502
        int from_h = disp_img.getHeight(null);
503
        if (from_w < 1 || from_h < 1) {
504
            return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
505
        }
498
        Graphics rg = null;
506 499
        
507
        BufferedImage resp =
508
            new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
509
        Graphics rg = resp.createGraphics();
510
        
511
        double rat_w = (1d*w) / (1d*from_w);
512
        double rat_h = (1d*h) / (1d*from_h);
513
        int offset_w = 0;
514
        int offset_h = 0;
515
        Image aux = null;
500
        try {
501
            if (disp_img == null || w < 1 || h < 1) {
502
                return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
503
            }
504
            int from_w = disp_img.getWidth(null);
505
            int from_h = disp_img.getHeight(null);
506
            if (from_w < 1 || from_h < 1) {
507
                return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
508
            }
509
            
510
            BufferedImage resp =
511
                new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
512
            rg = resp.createGraphics();
513
            
514
            double rat_w = (1d*w) / (1d*from_w);
515
            double rat_h = (1d*h) / (1d*from_h);
516
            int offset_w = 0;
517
            int offset_h = 0;
518
            Image aux = null;
516 519

  
517
        if (rat_w <= rat_h) {
518
            // apply resize of width
519
            int target_h = Math.max(1, (int) (from_h * rat_w));
520
            // w, target_h
521
            offset_w = 0;
522
            offset_h = (h - target_h) / 2;
523
            aux = disp_img.getScaledInstance(w, target_h, Image.SCALE_FAST);
524
            rg.drawImage(aux, offset_w, offset_h, null);
520
            if (rat_w <= rat_h) {
521
                // apply resize of width
522
                int target_h = Math.max(1, (int) (from_h * rat_w));
523
                // w, target_h
524
                offset_w = 0;
525
                offset_h = (h - target_h) / 2;
526
                aux = disp_img.getScaledInstance(w, target_h, Image.SCALE_FAST);
527
                rg.drawImage(aux, offset_w, offset_h, null);
525 528

  
526
        } else {
527
            // apply resize from height
528
            int target_w = Math.max(1, (int) (from_w * rat_h));
529
            // target_w, h
530
            offset_w = (w - target_w) / 2;
531
            offset_h = 0;
532
            aux = disp_img.getScaledInstance(target_w, h, Image.SCALE_FAST);
533
            rg.drawImage(aux, offset_w, offset_h, null);
529
            } else {
530
                // apply resize from height
531
                int target_w = Math.max(1, (int) (from_w * rat_h));
532
                // target_w, h
533
                offset_w = (w - target_w) / 2;
534
                offset_h = 0;
535
                aux = disp_img.getScaledInstance(target_w, h, Image.SCALE_FAST);
536
                rg.drawImage(aux, offset_w, offset_h, null);
537
            }
538
            
539
            aux = null;
540
            resp.flush();
541
            rg.dispose();
542
            return resp;
543
        } catch (Throwable th) {
544
            logger.info("While resizing image.", th);
545
            if (rg != null) {
546
                rg.dispose();
547
            }
548
            return null;
534 549
        }
535 550
        
536
        aux = null;
537
        resp.flush();
538
        rg.dispose();
539
        return resp;
540 551
    }
541 552

  
542 553
    protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout){

Also available in: Unified diff