Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Problem during writing of rendered image to stream

Last post 04-06-2009, 12:16 PM by alcrus. 2 replies.
Sort Posts: Previous Next
  •  04-03-2009, 8:55 AM 173314

    Problem during writing of rendered image to stream Java

    We 've stumbled upon several issues with EmfMetafile rendering of metafiles copied from MS Office.

    1. How are the dimensions of default rendered image computed? EmfMetafile.createDefaultRendering() returns large rendered images under circumstances we have not been able to pinpoint.
    2. Does EmfMetafile.createScaledRendering(int w, int h, java.awt.RenderingHints hints) execution time and memory consumption depend on width/height, and if so, how? 

      We need to create a rendered image from EMF
      1. fast (to be used for a paste function)
      2. not using a lot of memory
    3. Using the following code we want to render an EnhMetafile with certain dimensions :

      RenderedImage rendImg = null;
      try {

       ByteArrayInputStream bis = new ByteArrayInputStream(contents);
       EmfMetafile emf = new EmfMetafile(bis);

       float ratio = emf.getWidth()/emf.getHeight();
       final double MilliMetersPerInch = 25.4;
       int renderWidth = (int) ((width*toolkit.getScreenResolution())/MilliMetersPerInch);
       height = (int) (renderWidth/ratio);

       RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
       rendImg = emf.createScaledRendering(renderWidth, height, hints);
       
      } catch (MetafilesException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       try {
        ImageIO.write(rendImg, "png", bos);
       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
       
      Unfortunately ImageIO fails with the following stack trace :

      !STACK 0
      java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
       at java.awt.image.SinglePixelPackedSampleModel.getPixels(Unknown Source)
       at java.awt.image.Raster.getPixels(Unknown Source)
       at com.sun.imageio.plugins.png.PNGImageWriter.encodePass(Unknown Source)
       at com.sun.imageio.plugins.png.PNGImageWriter.write_IDAT(Unknown Source)
       at com.sun.imageio.plugins.png.PNGImageWriter.write(Unknown Source)
       at javax.imageio.ImageWriter.write(Unknown Source)
       at javax.imageio.ImageIO.write(Unknown Source)
       at javax.imageio.ImageIO.write(Unknown Source)
       
      This does not happen if we use emf.createDefaultRendering().
      Why would PNGImageWriter fail with this image, but not the default rendered? Is this a bug?


    Sakis Kotisis

    Senior Software Engineer

    SciGen Technologies, Inc.

    Office: +30 25410 25801
     
  •  04-06-2009, 10:27 AM 173586 in reply to 173314

    Re: Problem during writing of rendered image to stream

    Hello,

     

    I have forwarded your questions to technical team, it will answer you as soon as possible.


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  04-06-2009, 12:16 PM 173608 in reply to 173314

    Re: Problem during writing of rendered image to stream

    Hello Sakis,

    Coordinates of metafiles can start from negative value. In this case the only right way to render it is using code provided in our demo. It uses AffineTransform for translating coordinates. You only need change scale factor there.

    Alexey Zhilin
    Team Leader
    Aspose Tyumen Team
    About Us
    Contact Us
     
View as RSS news feed in XML