poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 57361] New: Cropping background images.
Date Wed, 17 Dec 2014 07:59:35 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=57361

            Bug ID: 57361
           Summary: Cropping background images.
           Product: POI
           Version: 3.10-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSLF
          Assignee: dev@poi.apache.org
          Reporter: artyom.nikiforov@arcusys.fi

Created attachment 32299
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=32299&action=edit
patch + samples of cropping the background images.

Hi, folks!
I'm trying to convert pptx slides to images with the code:
        FileInputStream is = new FileInputStream("slideshow.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        is.close();

        Dimension pgsize = ppt.getPageSize();

        Slide[] slide = ppt.getSlides();
        for (int i = 0; i < slide.length; i++) {

            BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            //clear the drawing area
            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width,
pgsize.height));

            //render
            slide[i].draw(graphics);

            //save the output
            FileOutputStream out = new FileOutputStream("slide-"  + (i+1) +
".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }

If background image is bigger than a slide, then it's cropped to a slide width
and height. So you get left top corner of an image as a result. If background
image is smaller, then it takes only a part of slide's area(see the attached
files).

BTW, I've made the changes in attached patch to eliminate the issue.

In the patch we just transform image to slide's size. Obviously the solution is
wrong, because we should preserve whole image unscaled till the last
render(otherwise we'll loose quality), but it solved the problem of cropping
the background image for me.

Artem

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message