poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr.jonze <mr.jo...@gmail.com>
Subject Re: Re[2]: PPT Pictures
Date Mon, 10 Jul 2006 14:29:06 GMT
Yes, it works the way it should. Thanks a lot.

2006/7/7, Yegor Kozlov <yegor@dinom.ru>:
>
> There are two ways to retrieve images from a ppt file:
>
> 1. Use  HSLFSlideShow.getPictureData().
> This method always returns the content of the image stream,
> It doesn't know if the images are used in the slides or not.
> I would say it corresponds to physical level, not to the logical, i.e.
> it returns images that are stored in  the ppt file, not the ones that
> are actually used.
> As Nick says, if you edit your ppt with 'incremental save' option
> enabled, HSLFSlideShow.getPictureData() can return previously deleted
> images which will be gone on next full resave.
>
> 2. Iterate over the shapes in a slide and collect Picture shapes.
> This approach guarantees that you get only those Pictures that are
> actually used:
>
>         Slide[] slide = ppt.getSlides();
>         for (int i = 0; i < slide.length; i++) {
>             Slide sl = slide[i];
>             Shape[] sh = sl.getShapes();
>             for (int j = 0; j < sh.length; j++) {
>                 Shape shape = sh[j];
>                 if (shape instanceof Picture){
>                     Picture picture = (Picture)shape;
>
>                     PictureData pict = picture.getPictureData();
>
>                     byte[] data = pict.getData();
>                     int type = pict.getType();
>
>                     if (type == Picture.JPEG){
>                         FileOutputStream out = new
> FileOutputStream("_slide"+j+".jpg");
>                         out.write(data);
>                         out.close();
>                     } else if (type == Picture.PNG){
>                         FileOutputStream out = new
> FileOutputStream("_slide"+j+".png");
>                         out.write(data);
>                         out.close();
>                     }
>                 }
>             }
>         }
>
> Yegor
>
> mj> Hi
>
> mj> I'd like to report an error that i found while using POI. I was
> retrieving
> mj> the pictures from a ppt file and saving each one in a file and it was
> mj> working ok, but i deleted one of the pictures of the PowerPoint file
> and POI
> mj> was still saving it in a file. Then I realized that it happens when
> the
> mj> source file of the picture is NOT a .PNG file. In this case, it
> happened
> mj> with a .BMP and a .JPG file.
>
> mj> Any suggestions?
>
> mj> Thanks,
> mj> mr_jonze.
>
> mj> 2006/7/3, Yegor Kozlov <yegor@dinom.ru>:
> >>
> >> Hi
> >>
> >> > For instance, if there are 3 pictures, being 2 of them the same
> picture,
> >> > the returned vector length is 2.
> >>
> >> It's how it is supposed to work. HSLFSlideShow.getPictures() returns
> the
> >> actual array of images contained in the presentation.
> >> Each image is included only once regardless of how many times you have
> it
> >> in the slides.
> >>
> >>
> >> > What can I do to get the real images number?
> >>
> >> It looks like you need the number of images shapes, not the number of
> >> actual images contained in the ppt.
> >>
> >> See the code:
> >>
> >>         SlideShow ppt = new SlideShow(new HSLFSlideShow("images.ppt"));
> >>
> >>         //images contained in this slide show
> >>         PictureData[] pict = ppt.getPictureData();
> >>
> >>         //get the number of image shapes
> >>         int imageCount = 0;
> >>         Slide[] slide = ppt.getSlides();
> >>         for (int i = 0; i < slide.length; i++) {
> >>             Shape[] sh = slide[i].getShapes();
> >>             for (int j = 0; j < sh.length; j++) {
> >>                 if (sh[j] instanceof Picture) {
> >>                     Picture p = (Picture)sh[j];
> >>                     PictureData pdata = p.getPictureData();
> >>
> >>                     imageCount++;
> >>                 }
> >>             }
> >>         }
> >>
> >> Since the same image can be placed on several slides imageCount may not
> >> equal to pict.length.
> >>
> >>
> >> Yegor
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> >> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> >> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> >>
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: poi-user-unsubscribe@jakarta.apache.org
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message