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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
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).
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.