Oliver Schmidtmer created PDFBOX-5378:
-----------------------------------------

             Summary: Slow rendering due to rescaling
                 Key: PDFBOX-5378
                 URL: https://issues.apache.org/jira/browse/PDFBOX-5378
             Project: PDFBox
          Issue Type: Bug
            Reporter: Oliver Schmidtmer
         Attachments: Test_2.pdf

Due to changes for better image quality when images are scaled down in 
[https://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?r1=1877290&r2=1877289&pathrev=1877290]
 the attached PDF renders much slower.

I propose to replace image.gerScaledInstance by
{code:java}
public BufferedImage getRescaledImage( BufferedImage image, int w, int h ) 
throws IOException {
 float scaleW = w / (( float )image.getWidth());
 float scaleH = h / (( float )image.getHeight());
 if(scaleW < .5f || scaleH < .5f){
  int nextW = scaleW <.5f ? ( int )Math.ceil( image.getWidth() / 2.0 ) : w;
  int nextH = scaleH <.5f ? ( int )Math.ceil( image.getHeight() / 2.0 ) : h;
  image = getRescaledImage( image, nextW, nextH );
 }
 int type = (image.getTransparency() == Transparency.OPAQUE) ?  
BufferedImage.TYPE_INT_RGB
 : BufferedImage.TYPE_INT_ARGB;
 BufferedImage scaled = new BufferedImage( w, h, type );
 Graphics2D g = scaled.createGraphics();
 g.setRenderingHint( RenderingHints.KEY_INTERPOLATION,  
RenderingHints.VALUE_INTERPOLATION_BILINEAR );
 g.drawImage( image, 0, 0, w, h, null );
 return scaled;
}{code}

While this implementations seems to be a bit slower than getScaledInstance, the 
 call to graphics.drawImage with the resulting BufferedImage seems to be 
significantly faster than drawing the ToolkitImage.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

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

Reply via email to