Menu

Very slow image creation

2005-05-19
2013-05-01
  • Nobody/Anonymous

    I'm not sure if this is a bug simply a feature of the j# code...but Image.GetInstance seems to be really slow for larger images. For example, the following code takes over 20 seconds to execute:

    System.Drawing.Bitmap bmap = new Bitmap(1440,2304);
    image = Image.getInstance(bmap);

    My application generates graphs and adds them to a PDF file. Creating 9 graphs takes around 15 seconds, but the Image.getInstance(bmap) calls end up taking 200+ seconds.

    Anything I can do to speed this up?

     
    • Kazuya Ujihara

      Kazuya Ujihara - 2005-05-20

      Image.getImage(Bitmap bitmap) is slow because the bitmap is converted to plain ARGB image using GetPixel and ToArgb. Use getInstance(byte[] image) rather than getImage(Bitmap).

       
    • Nobody/Anonymous

      WOW! That really made a difference. I changed my code to:

      System.Drawing.Bitmap bmap = CreateGraph(...);
      MemoryStream mstream = new MemoryStream();
                     
      bmap.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);
      mstream.Close();
      bmap.Dispose();
                     
      image = pdfutil.Image.getInstance(mstream.ToArray());

      The speedup was such that I cut my total runtime in half! Now the bottleneck is actually creating the graphs, not inserting them in the PDF.

      The Image.getInstance(byte[]) takes almost no time at all, whereas the Image.getInstance(Bitmap) is really slow.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.