Back to Devexpress

Export to Image

windowsforms-7323-controls-and-libraries-printing-exporting-concepts-exporting-export-to-image.md

latest4.0 KB
Original Source

Export to Image

  • Nov 15, 2018
  • 3 minutes to read

This document details the exporting of a document to Image.

The options that can be specified for a document exported to an image file are stored in the ImageExportOptions class, and can be accessed via a report’s ExportOptions.Image property.

Numerous image formats are supported, specified via the ImageExportOptions.Format property. They are listed below.

  • BMP;
  • EMF;
  • WMF;
  • GIF;
  • JPEG;
  • PNG;
  • TIFF.

Among these options, the ImageExportOptions.ExportMode property determines the way in which a document is exported to Image. For instance, it may be exported to a single file (with a single page header at the beginning and a single page footer at the end). Or it may be exported page-by-page to either a single file or different files.

To specify the quality of text rendering in images (especially in images having small dpi values and a transparent background), use the ImageExportOptions.TextRenderingMode property.

Example: How to Export a Report to Image Format

The following example demonstrates how to export a report to image format:

csharp
using System.Diagnostics;
using System.Drawing.Imaging;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...

namespace ExportToImageCS {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e) {
            // A path to export a report.
            string reportPath = "c:\\Test.png";

            // Create a report instance.
            XtraReport1 report = new XtraReport1();

            // Get its Image export options.
            ImageExportOptions imageOptions = report.ExportOptions.Image;

            // Set Image-specific export options.
            imageOptions.Format = ImageFormat.Png;

            // Export the report to Image.
            report.ExportToImage(reportPath);

            // Show the result.
            StartProcess(reportPath);
        }

        // Use this method if you want to automaically open
        // the created Image file in the default program.
        public void StartProcess(string path) {
            Process process = new Process();
            try {
                process.StartInfo.FileName = path;
                process.Start();
                process.WaitForInputIdle();
            }
            catch { }
        }
    }
}
vb
Imports System.Diagnostics
Imports System.Drawing.Imaging
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click
        ' A path to export a report.
        Dim reportPath As String = "c:\\Test.png"

        ' Create a report instance.
        Dim report As New XtraReport1()

        ' Get its Image export options.
        Dim imageOptions As ImageExportOptions = report.ExportOptions.Image

        ' Set Image-specific export options.
        imageOptions.Format = ImageFormat.Png

        ' Export the report to Image.
        report.ExportToImage(reportPath)

        ' Show the result.
        StartProcess(reportPath)
    End Sub

    ' Use this method if you want to automaically open
    ' the created Image file in the default program.
    Public Sub StartProcess(ByVal path As String)
        Dim process As New Process()
        Try
            process.StartInfo.FileName = path
            process.Start()
            process.WaitForInputIdle()
        Catch
        End Try
    End Sub
End Class