Skip to content

DevExpress-Examples/winforms-pictureedit-add-custom-graphic-operation-watermark

Repository files navigation

WinForms PictureEdit - Add custom graphic operations (watermarks) to the built-in image editor

The WinForms PictureEdit control integrates an image editor that allows users to perform common graphic operations:

  • Crop and straighten
  • Adjust brightness, contrast, and saturation
  • Mirror
  • Rotate, etc.

This example shows how to extend the image editor. The example adds custom commands that allow you to watermark the image:

WinForms PictureEdit - Watermark Images

  1. Create a BaseCachedGraphicOperation descendant class (WatermarkGraphicOperation). Users can undo and redo BaseCachedGraphicOperations while the image editor is active. See WatermarkToolControl.cs for implementation details.

  2. You can allow users to specify the operation's settings in custom controls before the operation is applied. Create a panel with controls and implement the IToolSettingsControl interface for the panel. The IToolSettingsControl.GetOperation method must return the customized graphic operation (WatermarkGraphicOperation).

    This example creates a user control (WatermarkToolControl) with controls to enter the watermark-related settings:

    • TextEditor to enter the watermark text
    • ColorEditor to specify the font color
    • SpinEditor to enter the font size
    • CheckEditor to allow the watermark text to be repeated throughout the image.
  3. Handle the PictureEdit.ImageEditorDialogShowing event to add custom commands (buttons) to the editor's main toolbar.

    This example adds two commands:

    • WatermarkPreset - Invokes the WatermarkGraphicOperation with predefined settings.
    • WatermarkCommand - Displays the WatermarkToolControl in which users can specify custom watermark settings and then apply the WatermarkGraphicOperation.

Files to Review