xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olivierk <okite...@gmail.com>
Subject What is the proper way to resize and embed an EPS image in another image?
Date Mon, 30 Jan 2012 16:56:57 GMT

I would like to embed one EPS image into another EPS image. The result would
be another EPS image. The background image represents a QR code, while the
embedded image represents a logo (please see the attached picture).
Depending on its height and width, the logo is scaled up or down to
predetermined dimensions before being embedded in the middle. The problem
is, when I write the combined images to a new file then open it with an EPS
viewer, the only thing I see is the background image (the QR code).
Can anyone tell me what I'm doing wrong? Here is how the image is supposed
to look like:  
 

http://old.nabble.com/file/p33230515/qr_code.png 
 
 

And here's the code:
 
 


           OutputStream out = new java.io.FileOutputStream(outputFile); 

            out = new java.io.BufferedOutputStream(out); 


            EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); 

            g2d.setGraphicContext(new
org.apache.xmlgraphics.java2d.GraphicContext()); 


            g2d.setupDocument(out, 500, 500); 


            g2d.drawRect(0, 0, 500, 500); 


            ImageManager imageManager = new ImageManager(new
DefaultImageContext()); 

            ImageSessionContext sessionContext = new
DefaultImageSessionContext(
                      imageManager.getImageContext(), null); 


            File baseDir = new File("k:\\Documents\\Desktop\\"); 

            File logoFile = new File(baseDir, "logo.eps"); 

            File barcodeFile = new File(baseDir, "qrcode.eps"); 

			
            ImageInfo logoInfo =
imageManager.getImageInfo(logoFile.toURI().toASCIIString(),
            sessionContext); 

            ImageInfo barcodeInfo =
imageManager.getImageInfo(barcodeFile.toURI().toASCIIString(),
            sessionContext); 


            ImageRawEPS rawEpsLogo =
(ImageRawEPS)imageManager.getImage(logoInfo, ImageFlavor.RAW_EPS,
sessionContext); 

            ImageRawEPS rawEpsBarcode =
(ImageRawEPS)imageManager.getImage(barcodeInfo, ImageFlavor.RAW_EPS,
sessionContext); 


            InputStream logoStream = new
BufferedInputStream(rawEpsLogo.createInputStream()); 

            InputStream qrcodeStream = new
BufferedInputStream(rawEpsBarcode.createInputStream()); 


            int barcodeW = barcodeInfo.getSize().getWidthMpt() / 1000; 

            int barcodeH = barcodeInfo.getSize().getHeightMpt() / 1000; 


            int logoW = logoInfo.getSize().getWidthMpt() / 1000; 

            int logoH = logoInfo.getSize().getHeightMpt() / 1000; 


            if (logoW >= barcodeW) 

             &nbsp         logoW = logoW/4; 

      
           if (logoH >= barcodeH) 

             &nbsp      logoH = logoH/4; 



            Rectangle viewport = new Rectangle(0, 0, barcodeW, barcodeH); 

            Rectangle bbox = new Rectangle(0, 0, barcodeW, barcodeH); 


            PSGenerator gen = g2d.getPSGenerator(); 



            PSImageUtils.renderEPS(qrcodeStream, "", viewport, bbox, gen); 


            //new rectange aligned in the middle-center 

            bbox  = new Rectangle( (barcodeW-logoW ) / 2, (barcodeH-logoH )
/ 2,
            logoW, logoW); 

            PSImageUtils.renderEPS(logoStream, "", viewport, bbox, gen); 


            g2d.finish();

 
 

-- 
View this message in context: http://old.nabble.com/What-is-the-proper-way-to-resize-and-embed-an-EPS-image-in-another-image--tp33230515p33230515.html
Sent from the Xml Graphics - General mailing list archive at Nabble.com.

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