IPersistableImageFormat Interface

Members   Example

Namespace: Fusion8.Cropper.Extensibility

The basic required interface implemented by community plug-ins. Cropper requires this interface to be implemented in order to find and load the plug-in.

  public interface IPersistableImageFormat

Example

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using Fusion8.Cropper.Extensibility;

public class PngFormat : IPersistableImageFormat
{
    private IPersistableOutput output;
    private const string formatName = "Png";
    private const string description = "Png Format";

    #region IPersistableImageFormat Implementation

    public event ImageFormatClickEventHandler ImageFormatClick;

    public IPersistableImageFormat Format
    {
        get { return this; }
    }

    public string Extension
    {
        get { return formatName; }
    }

    public string Description
    {
        get { return Description; }
    }

    public MenuItem Menu
    {
        get
        {
            MenuItem mi = new MenuItem();
            mi.RadioCheck = true;
            mi.Text = formatName;
            mi.Click += new EventHandler(MenuItemClick);
            return mi;
        }
    }

    public void Connect(IPersistableOutput persistableOutput)
    {
        if (persistableOutput == null)
            throw new ArgumentNullException("persistableOutput");

        output = persistableOutput;
        output.ImageCaptured += 
            new ImageCapturedEventHandler(HandleImageCaptured);
    }

    public void Disconnect()
    {
        output.ImageCaptured -= 
            new ImageCapturedEventHandler(HandleImageCaptured);
    }

    #endregion

    private void HandleImageCaptured(object sender, ImageCapturedEventArgs e)
    {
        output.FetchOutputStream(new StreamHandler(SaveImage),
                                 e.ImageNames.FullSize, e.FullSizeImage);
        
        if (e.IsThumbnailed)
            output.FetchOutputStream(new StreamHandler(SaveImage),
                                     e.ImageNames.Thumbnail, e.ThumbnailImage);
    }

    private void SaveImage(Stream stream, Image image)
    {
        image.Save(stream, ImageFormat.Png);
    }

    private void MenuItemClick(object sender, EventArgs e)
    {
        ImageFormatEventArgs formatEvents = new ImageFormatEventArgs();
        formatEvents.ClickedMenuItem = (MenuItem) sender;
        formatEvents.ImageOutputFormat = this;
        OnImageFormatClick(sender, formatEvents);
    }

    private void OnImageFormatClick(object sender, ImageFormatEventArgs e)
    {
        ImageFormatClickEventHandler handler = ImageFormatClick;
        if (handler != null)
            handler(sender, e);
    }
}

Last edited Feb 24, 2007 at 4:24 PM by BrhineScot, version 17

Comments

No comments yet.