Sign In  Sign Up Live-Chat

Exception when creating a buffered image to the Size of the WMF image

Last post 02-27-2008, 11:44 PM by alcrus. 10 replies.
Sort Posts: Previous Next
  •  11-27-2007, 5:04 AM 104053

    Exception when creating a buffered image to the Size of the WMF image

    Hi

    We are trying to print WMF images in MAC, so we are loading the images and create Buffered image for printing. Below is the code snippet which is causing the problem.

     WmfMetafile emfImg=new WmfMetafile(new ByteArrayInputStream(stMetaFileData));
      int ht=module.getHeight();
      int w=module.getWidth();
      
      double reductionHt=(ht/emfImg.getHeight());
      double reductionW=(w/emfImg.getWidth());
      
      BufferedImage imgBuffer=new BufferedImage((int)Math.ceil(emfImg.getWidth()),(int)Math.ceil(emfImg.getHeight()),BufferedImage.TYPE_3BYTE_BGR);

    Exception is thrown on creation of buffered image.(see the below stack trace). When i debugged the code i found the image dimension was 150912 X 93491. emfImg.getHeight() method was returning 150912 and emfImg.getWidth() method was returning 93491. When i see the image in windows it shows dimension 1024 X 768 the file size is 1 KB.

    java.lang.NegativeArraySizeException
     at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
     at
    java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
     at java.awt.image.BufferedImage.<init>(BufferedImage.java:370)
     at
    com.newsamerica.smartsource.presentation.CCMMetafile.showAt(CCMMetafile.
    java:56)
     at
    com.newsamerica.smartsource.presentation.CCMOffer.showAt(CCMOffer.java:7
    4)
     at
    com.newsamerica.smartsource.presentation.CCMManager.print(CCMManager.jav
    a:423)
     at
    sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1790)
     at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1338)
     at sun.print.UnixPrintJob.printableJob(UnixPrintJob.java:618)
     at sun.print.UnixPrintJob.print(UnixPrintJob.java:475)
     at
    com.newsamerica.smartsource.presentation.CCMManager.printCoupons(CCMMana
    ger.java:223)
     at

    Any input or direction to solve this issue will be appreciated

    regards

    Premkumar

     

     

     

     

     
  •  11-29-2007, 7:35 AM 104491 in reply to 104053

    Re: Exception when creating a buffered image to the Size of the WMF image

    Attachment: Present (inaccessible)

    Dear Premkumar

    I have run the following code on Windows XP and Aspose.Metafiles 1.2.4.0 and my finding is that Aspose.Metafiles returning the correct image height and width. I have attached the image, please check it on your side. Also, let me know, if the problem occurs for all images on MAC or with specific images.

    String strPath="D:\\source\\wmfs\\";

    WmfMetafile wmf = new WmfMetafile(new FileInputStream(new File(strPath + "1.wmf")));

    double reductionHt=wmf.getHeight();

    double reductionW=wmf.getWidth();


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Engineer
    Aspose Tyumen Team
     
  •  11-29-2007, 10:46 AM 104532 in reply to 104053

    Re: Exception when creating a buffered image to the Size of the WMF image

    Hello Premkumar,

    Non-placeable Wmf metafiles don't contain any exact size in the file.
    They usually have size equal to screen resolution.

    Could you try to call these lines of code on Mac and check result.
    float dpi = Toolkit.getDefaultToolkit().getScreenResolution();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    I'm not sure but most probably you will get screen size 150912 x 93491.
    So solution will be very simple, just divide width and height by some
    appropriate constant, for example 144 (in case size returned in twips).

    Alexey Zhilin
    Team Leader
    Aspose Tyumen Team
    About Us
    Contact Us
     
  •  11-29-2007, 10:49 AM 104534 in reply to 104053

    Re: Exception when creating a buffered image to the Size of the WMF image

    Hi  Faiz,

    The problem is not the loading the WMF image,  Once the image gets loaded in i am trying to create a Buffered image(Step 8 in below snippet) equal to size of the WMF height and width. But this step creates an NegativeArraySizeException. I guess it because of the height(93491) and width(150912) which too large and i get Out of Memory excetion in applet. This happens from some images.

    byte [] stMetaFileData;

    ......

    ......

    1. WmfMetafile emfImg=new WmfMetafile(new ByteArrayInputStream(stMetaFileData));
    2.  int ht=module.getHeight();
    3.  int w=module.getWidth();
    4  
    5  double reductionHt=(ht/emfImg.getHeight());
    6 double reductionW=(w/emfImg.getWidth());
    7  
    8  BufferedImage imgBuffer=new BufferedImage((int)Math.ceil(emfImg.getWidth()),(int)Math.ceil(emfImg.getHeight()),BufferedImage.TYPE_3BYTE_BGR);

    I have few more questions to ask

    1. What is the method should i use to get the image dimension, should i use getBounds() or the getHeight() and getWidth() methods.

    2. How to used apose jar when using applet in jar, when in put the aspose jar inside applet jar its unable to detect the classes. Kindly suggest the the best way to use aspose library in deployable applet jar.

    regards

    Premkumar

     

     

     

     
  •  11-29-2007, 10:57 AM 104537 in reply to 104532

    Re: Exception when creating a buffered image to the Size of the WMF image

    Hi Zhilin,

    I tried to load the same image i both  windows and MAC. The getHeight() method was returning 93491 and the getWidth() method was returning 150912. The getBounds() was having a value [0,0,150912,93491]. Is it a problem with the image?. There are some other image for which i was getting the bounds as [0,0,1024,768].

    Thanks in advance

    Premkumar

     
  •  11-29-2007, 11:31 AM 104545 in reply to 104534

    Re: Exception when creating a buffered image to the Size of the WMF image

    As I wrote in previous post wmf files can be placeable and non-placeable. Placeable metafiles have exact image size in the header. Non-placeable don't have it. So if size is too large use the solution I suggested before.

    About 2 other you questions.

    1. You can find answer in the api reference:
      /**
       * Returns metafile's bounds.<br>
       * Note: this rectangle is not an image size. To obtain image size and position use
       * getMinX(), getMinY(), getWidth() and getHeight().
       *
       * @return metafile's bounds.
       */
      public Rectangle getBounds()

    2. Try to google how to use several jar files in the applets and about jar caching.

    Alexey Zhilin
    Team Leader
    Aspose Tyumen Team
    About Us
    Contact Us
     
  •  11-29-2007, 11:37 AM 104548 in reply to 104545

    Re: Exception when creating a buffered image to the Size of the WMF image

    Hi Zhilin,

     Many Thanks for your quick response. I would try as per your suggession.

    regards

    Premkumar

     

     
  •  02-26-2008, 1:25 AM 114885 in reply to 104491

    wmf meta file reading in aspose

    I tried with aspose wmfmeta file to read the word art file in word document , but failed to do so. as null pointer returned.

    can u suggest one way to do this
     
  •  02-26-2008, 1:39 AM 114888 in reply to 114885

    Re: wmf meta file reading in aspose

    WordArt object is not a metafile.

    Alexey Zhilin
    Team Leader
    Aspose Tyumen Team
    About Us
    Contact Us
     
  •  02-27-2008, 11:19 PM 115269 in reply to 114888

    Re: wmf meta file reading in aspose

    so how to read a wordart file in word document
     
  •  02-27-2008, 11:44 PM 115273 in reply to 115269

    Re: wmf meta file reading in aspose

    I think you should write this question in the Aspose.Words forum. Just keep in mind,
    you should ask about WordArt but not about metafiles like you asked here.

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