Skip to main content

XRPictureBox Class

A Picture Box control that is used to display an image in a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v23.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

[DefaultBindableProperty("ImageSource")]
public class XRPictureBox :
    XRControl,
    IEditOptionsContainer

Remarks

You can use the XRPictureBox control to embed static (stored with the report definition) or dynamic (obtained from a data source) images into a report. The images can have one of the following formats: BMP, JPG, JPEG, GIF, TIF, TIFF, PNG, ICO, DIB, RLE, JPE, JFIF, EMF, WMF, SVG.

To add the PictureBox control to a report in Visual Studio, drag the XRPictureBox item from the DX.23.2: Report Controls Toolbox tab and drop it onto the report.

Versions_DropControl_XRPictureBox

Bind a Picture Box to an Image File

Specify the following properties to set an image:

xrpicturebox-02

Note

After the ImageUrl property is specified, the ImageSource property is set to null (Nothing in Visual Basic).

After the ImageSource property is specified, the ImageUrl property is set to Empty.

Tip

Use the ImageUrl property to specify a relative path to an image.

Load SVG Image

The ImageSource property accepts an instance of the DevExpress.XtraPrinting.Drawing.ImageSource class. To display an SVG image in an XRPictureBox, pass an SvgImage object to the ImageSource.ImageSource(SvgImage) constructor. You can create an SvgImage object with the following methods:

Image File in a Web Application

The use of the file:// protocol is not allowed in web applications for security reasons. If XRPictureBox cannot access the specified path, the image size is set to zero. To make relative file paths work, follow the steps below:

  1. Set the image root directory:

    AppDomain.CurrentDomain.SetData("DXResourceDirectory", @"C:\Pictures");
    
  2. Permit reading from the directory:

    AccessSettings.StaticResources.TrySetRules(DirectoryAccessRule.Allow(@"C:\Pictures"));
    
  3. Verify that the path is correct:

    string x; 
    UrlResolver.Instance.TryMapPath("~/myImage.png", out x);
    

Review the following help topic for more information: ImageUrl.

Bind a Picture Box to Data

Use one of the options listed below to add the XRPictureBox control, whose function it is to obtain an image from a data source.

  • Invoke the control’s smart tag, expand the Expression drop-down list for the ImageSource property, and select a data field.

    report-control-picturebox-0

    You can bind the ImageUrl property to data in a similar way. The URL that specifies the image location is obtained from the data source.

    Click the Expression property’s ellipsis button to invoke the Expression Editor. Use this editor to specify a binding expression that can include two or more data fields.

  • Drag an image data field from the report’s Field List and drop it onto a report band.

  • Right-click a data field in the Field List and drop it onto a report band. Select the PictureBox item in the invoked context menu.

    DesignTimeFeatures - FieldList4.png

  • See the Bind Report Controls to Data topic for more information on the available data binding modes and how to create data-aware controls.

You can bind the XRPictureBox control to the following image types:

  • Image
  • SvgImage
  • XML-formatted SVG
  • Byte Array received from an SVG string or an Image
  • Base64-encoded image data (see the Examples section for a code sample)

Note

XRPictureBox does not detect the field type or limit the acceptable types. It is the data source’s responsibility to specify the field type.

SVG Support Limitations

DevExpress controls support only base SVG elements and features. For the list of unsupported elements, review the following help topic: How To: Draw and Use SVG Images.

Export (except for PDF) has the following limitations:

  • SVG images are converted to metafiles because document viewers may not support SVG format.

  • SVG images are exported as PNG in the Microsoft Azure environment.

The application’s Medium Trust permission level does not support SVG.

Image Size Modes

Set the XRPictureBox.Sizing property to one of the available image size modes to specify how to position an image within the control.

Illustration

Description

ImageSizeMode-Normal

ImageSizeMode.Normal

The image is displayed with its original dimensions.

ImageSizeMode-StretchImage

ImageSizeMode.StretchImage

The image is stretched to fill both the control’s width and height.

ImageSizeMode-AutoSize

ImageSizeMode.AutoSize

The control’s dimensions are auto-adjusted to the image size.

ImageSizeMode-ZoomImage

ImageSizeMode.ZoomImage

The image is proportionally resized, so that it fits the control.

ImageSizeMode-Squeeze

ImageSizeMode.Squeeze

If the control’s dimensions exceed the image size, the image is centered and shown full-size.

Otherwise, the image is resized to fit into the control’s dimensions.

ImageSizeMode-Tile

ImageSizeMode.Tile

The original image is replicated within the picture control starting from the upper-left corner.

The replicated image is clipped if it does not fit in the picture control which contains it.

To display the image in the middle of the control, set the XRPictureBox.Sizing property to ImageSizeMode.Normal and the XRPictureBox.ImageAlignment property to ImageAlignment.MiddleCenter.

Image Orientation

The XRPictureBox.UseImageMetadata property allows you to specify whether to take into account the Exif metadata orientation of the image displayed in the XRPictureBox control.

The Exif orientation property helps applications display the image in its intended orientation, regardless of how it was captured by the camera. This property contains a numerical value that specifies how much a saved image should be rotated to achieve a correct viewing angle.

For example, if you capture a photo in portrait mode (holding the camera vertically), the camera may save the image in a landscape orientation. This can lead to the image appearing sideways or upside down when viewed on a computer or other devices.

When you set UseImageMetadata to true, the XRPictureBox control reads the orientation property value and displays the image according to this value.

The example below illustrates the use of UseImageMetadata. The XRPictureBox displays an image whose orientation in Exif metadata is 90 degrees clockwise. If you enable the UseImageMetadata property, the image is rotated 90 degrees clockwise to orientate it correctly.

XRPictureBox image orientation

Interactivity

You can add a possibility to load/change an image and/or draw a signature in a picture box when it is displayed in Print Preview. To do this, set the EditOptions.Enabled property to true.

picture-box-enable-content-editing

Click the picture box in a previewed document to invoke an editor.

picture-box-content-editing

Tip

You can draw borders for the picture box to make the editor visible in Print Preview if an image is not specified.

Refer to the Edit Content in Print Preview topic for details and to the Create an Interactive E-Form in the Visual Studio Report Designer tutorial to see how the E-Form demo report uses this picture box mode.

Examples

This example demonstrates how to create an XRPictureBox object and specify its properties.

using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.XtraReports.UI;
using System.Drawing;
// ...
public XRPictureBox CreateXRPictureBox()
{
    // Create an XRPictureBox instance.
    XRPictureBox xrPictureBox = new XRPictureBox();

    // Specify an image for the created XRPictureBox instance.
    xrPictureBox.ImageSource = ImageSource.FromFile("Images\\Flags\\United_States_of_America.png");
    // Uncomment these lines to get images from a data source.
    // ExpressionBinding expressionBinding = new ExpressionBinding("BeforePrint", "ImageSource", "[Picture]");
    // xrPictureBox.ExpressionBindings.Add(expressionBinding);

    // Position the picture box within a document.
    xrPictureBox.LocationF = new PointF(150F, 25F);

    // Set the picture box size.
    xrPictureBox.SizeF = new SizeF(160F, 120F);

    // Set the picture box size mode.
    xrPictureBox.Sizing = ImageSizeMode.AutoSize;

    // Specify that the image in the picture box should use the default DPI value.
    xrPictureBox.UseImageResolution = false;

    return xrPictureBox;
}

The following example shows how to bind an XRPictureBox to a Base64-encoded image stored in a JSON data source.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.DataAccess.Json;
// ...

XtraReport report = new XtraReport() {
    Bands = {
        new DetailBand() {
            Controls = {
                new XRLabel() {
        BoundsF = new RectangleF(0,0,150,25),
                    ExpressionBindings = {
                        new ExpressionBinding("Text","[CompanyName]")
                    }
                },
                new XRLabel() {
                    BoundsF = new RectangleF(200,0,150,25),
                    ExpressionBindings = {
                        new ExpressionBinding("Text","[CompanyUrl]")
                    }
                },
                new XRPictureBox() {
                    BoundsF = new RectangleF(400,0,150,25),
                    ExpressionBindings = {
                        new ExpressionBinding("ImageSource","[CompanyLogo]")
                    }
                }
            }
        }
    }
};
string json = "[{\"CompanyName\":\"DevExpress\",\"CompanyUrl\":\"www.devexpress.com\",\"CompanyLogo\":\"iVBORw0KGgoAAAANSUhEUgAAAJQAAAAZCAYAAADXEgfSAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH4wgVDS4da2rZRgAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJdEVYdFNvZnR3YXJlAF1w / zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDAG + aHAAAAB3RFWHRTb3VyY2UA9f + D6wAAAAh0RVh0Q29tbWVudAD2zJa / AAAABnRFWHRUaXRsZQCo7tInAAARJ0lEQVRoge2ba3CT15nHf5JeXWzLGMuyJF8kyxeMbyy2weZSHBwHnIBTSGh3KW2atuk2ZTM7ne12p1922t1OO / uts9PpTG77JdtMAiQNJClp02zCxcbYEDA2 + AaWLPkuy5Itybbul / 2g8iaKgZCEkmWH / 4zGmuNznvOcc / 7nnOdyJLl0qTfx6quHWFxc4k5AEASqqtayd + 9e8vPz74jM + 7h3ILzwwotMT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Jem4HDhzgj3/8E+PjY8zPL5CRkc6aNWtobm6msXFjSgJ7xfocPPhM4k6/Kc/IyKCtbRdPPPGtOyLz/wP6+wf43e9eFjfQU099l4cfbiU9Pf1TWt5bEH74w6c5dOjIimvn80IuT+7ylpYH74i8+7i3INTWrqe29tND6vdxH7eDu/NY+z6QyWSkp6eL7rdcLr+rP8C4W/hfxrjfFFxJd4wAAAAASUVORK5CYII=\"}]";
JsonDataSource jsonDataSource = new JsonDataSource();
jsonDataSource.JsonSource = new CustomJsonSource(json);
jsonDataSource.Fill();
report.DataSource = jsonDataSource;
report.ShowPreview();

Implements

See Also