search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

MemoryStream error when exporting to PNG several items

Asked by Cesar Duran
9 years ago.

I followed the tutorial to create a print button that calls the file png.aspx which has all the configuration to export the scheduler to PNG.

The solution works fine as long a I don't select too much data for the scheduler control, I'm trying to print around 3700 items and the error appears to be on the MemoryStream (see error on the screenshot I'm attaching)

I know that in order to load several items on the calendar I need to use the Progressive rendering which I already did, here are the the settings that I used but I'm still unable to make it my code works, I'm also including the code behind file of my png page

DayPilotScheduler1.DynamicEventRendering = EventRendering.Progressive;
DayPilotScheduler1.DynamicEventRenderingCacheSize = 200;
DayPilotScheduler1.DynamicEventRenderingCacheSweeping = false;
DayPilotScheduler1.DynamicEventRenderingMargin = 50;
DayPilotScheduler1.DynamicLoading = false;

Comment posted by Dan Letecky [DayPilot]
9 years ago.

I can see that it is throwing ArgumentException. Could you please post the full exception stack trace here?

Comment posted by Cesar Duran
9 years ago.

Sure, also I noticed that playing with the number of the rows to be displayed (from SQL) the export works when the output file is <2MB. I have read that I might need to split MemoryStream .. that could explain why it works until certain point before the file is too large.

at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at DayPilot.Web.Ui.Export.SchedulerExport.Export()
at DayPilot.Web.Ui.DayPilotScheduler.ExportBitmap()
at DayPilot.Web.Ui.DayPilotScheduler.Export(ImageFormat format)
at Project_Default.ExportToPng() in d:\Development\ProgramPlan\Default.aspx.cs:line 225

Comment posted by Dan Letecky [DayPilot]
9 years ago.

It looks like the config you are using (the number of resources*timeline) is resulting in a bitmap size that is too big for .NET. See also:

http://stackoverflow.com/questions/6333681/c-sharp-parameter-is-not-valid-creating-new-bitmap

It might not be possible to export such a big grid as a single bitmap....

Note that the dynamic loading properties have no effect during export.

Comment posted by Dan Letecky [DayPilot]
9 years ago.

However, 2MB doesn't sound like too much. How many resources do you display? And what is the timeline width?

Comment posted by Anonymous
9 years ago.

Timeline is 13 days, resources are 6 and the number of items when starts crashing is around 500.

I believe is not that much information considering daypilot pro supports thousands of items. I'm planning to add more filtering options to reduce the number of items of the output to prevent this error, but it would be preferable to have all items at once to print the entire plan in a plotter.

Answer posted by Dan Letecky [DayPilot]
9 years ago.

It looks like it is not the number of resources or the timeline length that is causing the problem. It is the absolute image size.

I did a few tests. I've added the image export button to the following page:

http://www.daypilot.org/demo/Scheduler/ProgressiveEventRendering.aspx

It displays about 10,000 events. I've adjusted it to print the full width:

DayPilotScheduler1.Width = Unit.Percentage(100);  // use Unit.Percentage(100) for full width

The output is 14,720 x 740 pixels, about 373 kB.

I have increased the event height to 100 pixels to make the output bigger:

        DayPilotScheduler1.EventHeight = 100;

This produces 14,720 x 2840 pixel image, about 1.1 MB.

Increasing the cell width to 60 still works:

        DayPilotScheduler1.CellWidth = 60;

This produces 20,020 x 2840 pixel image, about 1.25 MB.

After that point, it starts throwing OutOfMemory exceptions. Increasing CellWidth to 600 throws the ArgumentException you are getting:

[ArgumentException: Parameter is not valid.]
   System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) +1145281
   System.Drawing.Bitmap..ctor(Int32 width, Int32 height) +18
   DayPilot.Web.Ui.Export.SchedulerExport.Export() in C:\Users\Hynek\Documents\Visual Studio 2010\Projects\DayPilot\Source\Web\Ui\Export\SchedulerExport.cs:151
   DayPilot.Web.Ui.DayPilotScheduler.ExportBitmap() in C:\Users\Hynek\Documents\Visual Studio 2010\Projects\DayPilot\Source\Web\Ui\DayPilotScheduler.cs:6049
   DayPilot.Web.Ui.DayPilotScheduler.Export(ImageFormat format) in C:\Users\Hynek\Documents\Visual Studio 2010\Projects\DayPilot\Source\Web\Ui\DayPilotScheduler.cs:6028
   ...

So there is clearly a limit of what the .NET image API can handle.

The output image size might seem small but PNG uses compression that is very effective for this kind of bitmap. The memory required for 20,020 x 2,840 bitmap is 20,020 * 2,840 * 32 bits = 227,427,200 bytes.

Comment posted by Dan Letecky [DayPilot]
9 years ago.

I assume the only reason for making the output image big is the print quality (stretching the standard image output doesn't look good). The only solution that makes sense is to export the image in a vector format. .NET doesn't support SVG out of the box but EMF might be an option.

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.