View | Details | Raw Unified | Return to bug 58190
Collapse All | Expand All

(-)a/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java (-5 / +4 lines)
Lines 19-31 Link Here
19
19
20
package org.apache.poi.xslf.usermodel;
20
package org.apache.poi.xslf.usermodel;
21
21
22
import org.apache.poi.util.IOUtils;
23
24
import java.io.File;
22
import java.io.File;
25
import java.io.FileInputStream;
23
import java.io.FileInputStream;
26
import java.io.FileOutputStream;
24
import java.io.FileOutputStream;
27
import java.io.IOException;
25
import java.io.IOException;
26
28
import org.apache.poi.sl.usermodel.PictureData.PictureType;
27
import org.apache.poi.sl.usermodel.PictureData.PictureType;
28
import org.apache.poi.util.IOUtils;
29
29
30
/**
30
/**
31
 * Images
31
 * Images
Lines 39-53 public class Tutorial5 { Link Here
39
39
40
        XSLFSlide slide = ppt.createSlide();
40
        XSLFSlide slide = ppt.createSlide();
41
        File img = new File(System.getProperty("POI.testdata.path"), "slideshow/clock.jpg");
41
        File img = new File(System.getProperty("POI.testdata.path"), "slideshow/clock.jpg");
42
        byte[] data = IOUtils.toByteArray(new FileInputStream(img));
42
        XSLFPictureData pictureIndex = ppt.addPicture(img, PictureType.PNG);
43
        XSLFPictureData pictureIndex = ppt.addPicture(data, PictureType.PNG);
44
43
45
        /*XSLFPictureShape shape =*/ slide.createPicture(pictureIndex);
44
        /*XSLFPictureShape shape =*/ slide.createPicture(pictureIndex);
46
45
47
        FileOutputStream out = new FileOutputStream("images.pptx");
46
        FileOutputStream out = new FileOutputStream("images.pptx");
48
        ppt.write(out);
47
        ppt.write(out);
49
        out.close();
48
        out.close();
50
        
49
51
        ppt.close();
50
        ppt.close();
52
    }
51
    }
53
}
52
}
(-)a/src/java/org/apache/poi/sl/usermodel/SlideShow.java (-2 / +24 lines)
Lines 18-24 Link Here
18
package org.apache.poi.sl.usermodel;
18
package org.apache.poi.sl.usermodel;
19
19
20
import java.awt.Dimension;
20
import java.awt.Dimension;
21
import java.io.File;
21
import java.io.IOException;
22
import java.io.IOException;
23
import java.io.InputStream;
22
import java.util.List;
24
import java.util.List;
23
25
24
import org.apache.poi.sl.usermodel.PictureData;
26
import org.apache.poi.sl.usermodel.PictureData;
Lines 48-59 public interface SlideShow { Link Here
48
    
50
    
49
51
50
    /**
52
    /**
51
     * Adds a picture to the workbook.
53
     * Adds a picture to the presentation.
52
     *
54
     *
53
     * @param pictureData       The bytes of the picture
55
     * @param pictureData       The bytes of the picture
54
     * @param format            The format of the picture.
56
     * @param format            The format of the picture.
55
     *
57
     *
56
     * @return the new picture reference
58
     * @return the picture data reference.
57
     */
59
     */
58
    PictureData addPicture(byte[] pictureData, PictureType format) throws IOException;
60
    PictureData addPicture(byte[] pictureData, PictureType format) throws IOException;
61
62
    /**
63
     * Adds a picture to the presentation.
64
     *
65
     * @param is	        The stream to read the image from
66
     * @param format        The format of the picture.
67
     *
68
     * @return the picture data reference.
69
     */
70
    PictureData addPicture(InputStream is, PictureType format) throws IOException;
71
72
    /**
73
     * Adds a picture to the presentation.
74
     *
75
     * @param pict              The file containing the image to add
76
     * @param format            The format of the picture.
77
     *
78
     * @return the picture data reference
79
     */
80
    PictureData addPicture(File pict, PictureType format) throws IOException;
59
}
81
}
(-)a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java (+45 lines)
Lines 17-22 Link Here
17
package org.apache.poi.xslf.usermodel;
17
package org.apache.poi.xslf.usermodel;
18
18
19
import java.awt.Dimension;
19
import java.awt.Dimension;
20
import java.io.File;
21
import java.io.FileInputStream;
20
import java.io.IOException;
22
import java.io.IOException;
21
import java.io.InputStream;
23
import java.io.InputStream;
22
import java.io.OutputStream;
24
import java.io.OutputStream;
Lines 463-468 public class XMLSlideShow extends POIXMLDocument implements SlideShow { Link Here
463
        return img;
465
        return img;
464
    }
466
    }
465
467
468
469
    /**
470
     * Adds a picture to the slideshow.
471
     *
472
     * @param is                The stream to read image from
473
     * @param type              The format of the picture
474
     *
475
     * @return the picture data
476
     */
477
    @Override
478
    public XSLFPictureData addPicture(InputStream is, PictureType format) throws IOException
479
    {
480
        return addPicture(IOUtils.toByteArray(is), format);
481
    }
482
483
484
    /**
485
     * Adds a picture to the presentation.
486
     *
487
     * @param pict             The file containing the image to add
488
     * @param format           The format of the picture.
489
     *
490
     * @return the picture data
491
     */
492
    @Override
493
    public XSLFPictureData addPicture(File pict, PictureType format) throws IOException
494
    {
495
        int length = (int) pict.length();
496
        byte[] data = new byte[length];
497
        FileInputStream is = null;
498
        try
499
        {
500
            is = new FileInputStream(pict);
501
            is.read(data);
502
        }
503
        finally
504
        {
505
            if (is != null) is.close();
506
        }
507
        return addPicture(data, format);
508
    }
509
510
466
    /**
511
    /**
467
     * check if a picture with this picture data already exists in this presentation
512
     * check if a picture with this picture data already exists in this presentation
468
     */
513
     */
(-)a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (-5 / +25 lines)
Lines 50-55 import org.apache.poi.sl.usermodel.PictureData.PictureType; Link Here
50
import org.apache.poi.sl.usermodel.Resources;
50
import org.apache.poi.sl.usermodel.Resources;
51
import org.apache.poi.sl.usermodel.Shape;
51
import org.apache.poi.sl.usermodel.Shape;
52
import org.apache.poi.sl.usermodel.SlideShow;
52
import org.apache.poi.sl.usermodel.SlideShow;
53
import org.apache.poi.util.IOUtils;
53
import org.apache.poi.util.POILogFactory;
54
import org.apache.poi.util.POILogFactory;
54
import org.apache.poi.util.POILogger;
55
import org.apache.poi.util.POILogger;
55
import org.apache.poi.util.Units;
56
import org.apache.poi.util.Units;
Lines 797-812 public final class HSLFSlideShow implements SlideShow { Link Here
797
	}
798
	}
798
799
799
	/**
800
	/**
800
	 * Adds a picture to this presentation and returns the associated index.
801
	 * Adds a picture to the presentation.
802
	 *
803
	 * @param is	        The stream to read the image from
804
	 * @param format        The format of the picture.
805
	 *
806
	 * @return the picture data.
807
	 */
808
	@Override
809
	public HSLFPictureData addPicture(InputStream is, PictureType format) throws IOException {
810
	    if (format == null || format.nativeId == -1) { // fail early
811
	        throw new IllegalArgumentException("Unsupported picture format: " + format);
812
	    }
813
	    return addPicture(IOUtils.toByteArray(is), format);
814
	}
815
816
	/**
817
	 * Adds a picture to the presentation.
801
	 *
818
	 *
802
	 * @param pict
819
	 * @param pict
803
	 *            the file containing the image to add
820
	 *            the file containing the image to add
804
	 * @param format
821
	 * @param format
805
	 *            the format of the picture. One of constans defined in the
822
	 *            The format of the picture.
806
	 *            <code>Picture</code> class.
823
	 *
807
	 * @return the index to this picture (1 based).
824
	 * @return the picture data.
808
	 */
825
	 */
826
	@Override
809
	public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
827
	public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
828
	    if (format == null || format.nativeId == -1) { // fail early
829
	        throw new IllegalArgumentException("Unsupported picture format: " + format);
830
	    }
810
		int length = (int) pict.length();
831
		int length = (int) pict.length();
811
		byte[] data = new byte[length];
832
		byte[] data = new byte[length];
812
        FileInputStream is = null;
833
        FileInputStream is = null;
813
- 

Return to bug 58190