5,427,303 members and growing! (20,195 online)
Email Password   helpLost your password?
Multimedia » GDI+ » General     Intermediate

A simple Windows Forms image viewer

By corvado

This is a simple viewer application which allows you to apply basic operation on images such as Rotate, Flip, ROI (Region of interest) zoom and Panning.
C#, Windows, .NET 1.0, .NETVisual Studio, VS.NET2002, Dev

Posted: 31 Jan 2003
Updated: 31 Jan 2003
Views: 75,374
Bookmarked: 32 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
19 votes for this Article.
Popularity: 4.89 Rating: 3.82 out of 5
0 votes, 0.0%
1
2 votes, 10.5%
2
3 votes, 15.8%
3
4 votes, 21.1%
4
10 votes, 52.6%
5

Sample Image - LimfROI.jpg
Sample Image - LimfROI2.jpg

Introduction

This is a simple viewer application which allows you to apply basic operation on images such as Rotate, Flip, ROI (Region of interest) zoom and Panning. It offers a sample example for the powerful Matrix class use and the way to have unclassical forms look. A simple windowing method is implemented using middle muse button (available for grayscale image).

Using the code

The interesting code is based on the DisplayPort class which acts as a viewport. A command mechanism is also develop to allow multiple DisplayPort to interact with the user cooperatively. Adding new behaviour such as displaying and designing graphics above the image is easy. See the DisplayLinkRind class which is a manager of simple text overlays.

To add a DisplayPort to a WindowsForm just add a member like this and chain the MouseDown event:

public LimfWnd()
{
    this.ClientSize = new System.Drawing.Size(464, 344);

    this.m_DisplayPort = new DisplayPort();

    InitializeComponent();

    this.m_DisplayPort.MouseDown += new MouseEventHandler(LimfWnd_MouseDown);

            ...

Then add the controls to the form:

private void InitializeComponent()
{
    // 

    // LimfWnd

    // 

    this.AllowDrop = true;
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.BackColor = System.Drawing.SystemColors.WindowText;

    this.ClientSize = new System.Drawing.Size(SystemInformation.WorkingArea.Width/2, 
                                              SystemInformation.WorkingArea.Height/2);

    this.Controls.AddRange(new System.Windows.Forms.Control[] {this.m_DisplayPort,
                                                                          this.splitter1});

            ...

Add image to the DisplayPort:

private void LoadImage(object sender, System.EventArgs e)
{
    FileDialog  Boite = new OpenFileDialog();
    Boite.ShowDialog();

    if(Boite.FileName.Length > 0)
    {
        Image Img = Image.FromFile(Boite.FileName);
        m_DisplayPort.SetImage(Img);
    }
}
            ...

Chain the menu list event:

private void LimfWnd_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if(e.Button == MouseButtons.Right)
    {
        CMenuActionList CommandsLst;

        if(sender.GetType() == m_DisplayPort.GetType())
            CommandsLst = ((DisplayPort) sender).GetCommand(null);
        else
            CommandsLst = new CMenuActionList();

        if(CommandsLst == null)
            CommandsLst = new CMenuActionList();

        CommandsLst.AddMenu(1, "Quit", 1, new System.EventHandler(Quit));
    

Points of Interest

The main difficulty was to create the basic rotate/flip routines to manage the coordinate converter. The only limit I found regarding the use of GDI+ was the 16 bits per pixel format which is not implemented, so no use for such images.

History

Version 1.0 is the first release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

corvado



Location: France France

Other popular GDI+ articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGreat Codememberafshin_a12:13 30 Jul '08  
GeneralGreat componentmemberathmok@yahoo.co.uk2:17 1 Feb '07  
GeneralGreat Samplemembervivekthangaswamy7:15 27 Jan '06  
Generalreally nice onememberricharding5:16 16 Jan '06  
GeneralGreat but needed in vb.netmemberchinnivenkat21:20 9 Aug '04  
GeneralRe: Great but needed in vb.netmemberchinnivenkat18:07 10 Aug '04  
GeneralGood job!memberdon!marco23:15 22 Jun '04  
GeneralDemo project liks MSCOREE.DLLmemberGeorgi Petrov3:06 5 May '04  
GeneralRe: Demo project liks MSCOREE.DLLmemberdon!marco23:19 22 Jun '04  
GeneralOne Really Weird Thing.memberkipling6:08 21 Feb '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 31 Jan 2003
Editor: Chris Maunder
Copyright 2003 by corvado
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project