1 31 package org.pdfbox.util.operator.pagedrawer; 32 33 import java.awt.Graphics2D ; 34 import java.awt.geom.AffineTransform ; 35 import java.awt.image.BufferedImage ; 36 import java.io.IOException ; 37 import java.util.List ; 38 39 import org.pdfbox.pdfviewer.PageDrawer; 40 import org.pdfbox.pdmodel.graphics.xobject.PDInlinedImage; 41 import org.pdfbox.util.ImageParameters; 42 import org.pdfbox.util.Matrix; 43 import org.pdfbox.util.PDFOperator; 44 import org.pdfbox.util.operator.OperatorProcessor; 45 46 52 public class BeginInlineImage extends OperatorProcessor 53 { 54 55 56 62 public void process(PDFOperator operator, List arguments) throws IOException 63 { 64 PageDrawer drawer = (PageDrawer)context; 65 Graphics2D graphics = drawer.getGraphics(); 66 ImageParameters params = operator.getImageParameters(); 68 PDInlinedImage image = new PDInlinedImage(); 69 image.setImageParameters( params ); 70 image.setImageData( operator.getImageData() ); 71 BufferedImage awtImage = image.createImage(); 72 73 Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix(); 74 75 int width = awtImage.getWidth(); 76 int height = awtImage.getHeight(); 77 78 79 AffineTransform at = new AffineTransform ( 80 ctm.getValue(0,0)/width, 81 ctm.getValue(0,1), 82 ctm.getValue(1,0), 83 ctm.getValue(1,1)/height, 84 ctm.getValue(2,0), 85 ctm.getValue(2,1) 86 ); 87 89 90 96 101 107 graphics.drawImage( awtImage, at, null ); 112 } 114 } 115 | Popular Tags |