RadiantQ WPF Gantt
How to Export Gantt as Image?
Previous Topic  Next Topic 

How to Export Gantt as Image?


Gantt can be exported as an image,

- for a specific date range 

- or row indices

- or the entire gantt.


...using this enhanced feature. 


Exported images can be saved in different formats. 


This is also illustrated in this sample that's part of our install: <install path>\Samples\Common\ImageExport


ExportAsImageUtil exportUtil = new ExportAsImageUtil();


exportUtil.ExportASImage(this.ganttControl, viewWidth, startDate, EndDate, indices, SelectedTasksFilter);



Sometimes you might want to simply get the generated image (and not allow the gantt to save it). You can do so by listening to the BeforeExporting event like this:


ExportAsImageUtil exportUtil = new ExportAsImageUtil();


// Event to get the image object while printing/exporting and to cancel the dafault functionality

exportUtil.BeforeExporting += exportUtil_BeforeExporting;


exportUtil.ExportASImage(this.ganttControl, viewWidth, startDate, EndDate, indices, SelectedTasksFilter);


void exportUtil_BeforeExporting(object sender, ExportAsImageUtil.CancellableExportAsImageEventArgs e)

{

    BitmapSource bs = e.BitmapSource;

    PngBitmapEncoder encoder = new PngBitmapEncoder();

    BitmapFrame outputFrame = BitmapFrame.Create(bs);

    encoder.Frames.Add(outputFrame);


    SaveFileDialog sfd = new SaveFileDialog()

         

    {

        DefaultExt =

        "bmp",

        Filter =

        "png files |*.png|All files (*.*)|*.*",

        FilterIndex = 1

    };


    if (sfd.ShowDialog() == true)

    {

        using (Stream stream = sfd.OpenFile())

        {

            encoder.Save(stream);

            stream.Close();

        }

    }


    // Set true to cancel default functionality

    e.Cancel = true;

}






� RadiantQ 2009 - 2019. All Rights Reserved.