2 Replies Latest reply: Sep 12, 2011 8:49 AM by 851713 RSS

    Strange Exception ( AffineTransform )

    851713
      Hi,

      Can someone tell me something usefull* about the following exception?
      Exception in thread "AWT-EventQueue-0" sun.dc.pr.PRError: setPenT4: invalid pen transformation (singular)
              at sun.dc.pr.PathStroker.setPenT4(Native Method)
              at sun.dc.pr.Rasterizer.setPenT4(Rasterizer.java:234)
              at sun.java2d.pipe.DuctusRenderer.createShapeRasterizer(DuctusRenderer.java:368)
              at sun.java2d.pipe.DuctusShapeRenderer.renderPath(DuctusShapeRenderer.java:97)
              at sun.java2d.pipe.DuctusShapeRenderer.draw(DuctusShapeRenderer.java:46)
              at sun.java2d.pipe.PixelToParallelogramConverter.draw(PixelToParallelogramConverter.java:130)
              at sun.java2d.pipe.ValidatePipe.draw(ValidatePipe.java:136)
              at sun.java2d.SunGraphics2D.draw(SunGraphics2D.java:2336)
              at ...
      Here is a try-out-app
      public class Test {
      
      public static void main(String[] args) {
      
      AffineTransform at = new AffineTransform();
      
      at.concatenate( AffineTransform.getShearInstance( 1.0D, 1.0D ) );
      
      createImageFromMutableShape( 500, 500, new RoundedRectangle2D.Double( 0.0D, 0.0D, 250.0D, 250.0D, 25.0D, 25.0D ), null, null, at, true, true );
      
      
      }
      
      public static BufferedImage getCompatibleBufferedImage( int width,
                  int height, boolean transparent ) {
              return transparent ? GraphicsUtilities.createCompatibleTranslucentImage(
                      width, height ) : GraphicsUtilities.createCompatibleImage( width,
                      height );
          }
      
          public static BufferedImage createImageFromMutableShape( int width,
                  int height, Shape shape, Shape paintShape, Paint paint,
                  AffineTransform at, boolean translucent, boolean aa ) {
              // create the raw image
              BufferedImage rc = getCompatibleBufferedImage( width, height,
                      translucent );
              // get the Graphics object
              Graphics2D g2d = rc.createGraphics();
              
              
              // set antialiasing
              if ( aa ) {
                  g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING,
                          RenderingHints.VALUE_ANTIALIAS_ON );
              }
              if ( at != null ) {
                  g2d.setTransform( at );
              }
              if ( paint != null ) {
                  g2d.setPaint( paint );
                  g2d.fill( shape );
              } else {
                  g2d.setColor( Color.red );
                  g2d.draw( shape );
              }
      
              g2d.dispose();
      
              return rc;
          }
      
      } 
      You need the SwingX-library installed too. If you don't want to install it, you need to create the
      compatible BufferedImage for yourself.

      Regards,
      Olek