Am 28.04.2015 um 07:37 schrieb John Hewson:
On 27 Apr 2015, at 14:03, Tilman Hausherr <thaush...@t-online.de> wrote:

Am 27.04.2015 um 20:08 schrieb John Hewson:
On 27 Apr 2015, at 08:52, Tilman Hausherr <thaush...@t-online.de> wrote:

          PDImageXObject pdImage;
            if (imagePath.toLowerCase().endsWith(".jpg"))
            {
                pdImage = JPEGFactory.createFromStream(doc, new 
FileInputStream(imagePath));
            }
            else if (imagePath.toLowerCase().endsWith(".tif") ||
                     imagePath.toLowerCase().endsWith(".tiff"))
            {
                pdImage = CCITTFactory.createFromFile(doc, new File(imagePath));
            }
            else if (imagePath.toLowerCase().endsWith(".gif") ||
                     imagePath.toLowerCase().endsWith(".bmp") ||
                     imagePath.toLowerCase().endsWith(".png"))
            {
                BufferedImage bim = ImageIO.read(new File(imagePath));
                pdImage = LosslessFactory.createFromImage(doc, bim);
            }
            else
            {
                throw new IOException("Image type not supported: " + imagePath);
            }
Tilman, maybe we could encapsulate this code in a static factory method, e.g. 
PDImageXObject.load(File)?
Yes, that's a good idea... the only thing that irritates me is that if we 
replace the above code with load(), the example will no longer show how to 
create an XImage from a BufferedImage.

Maybe we could have both in the example, or PDImageXObject.load(BufferedImage) 
too?

This would kindof "discriminate" against the jpeg method that also allows a BufferedImage, also also be duplicate. However I've put a javadoc that links the three methods, and also added a comment, see

PDFBOX-2777.


Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org

Reply via email to