65.9K
CodeProject 正在变化。 阅读更多。
Home

简单的Windows窗体图像查看器

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.28/5 (23投票s)

2003年2月1日

1分钟阅读

viewsIcon

138041

downloadIcon

2957

这是一个简单的查看器应用程序,允许您对图像执行基本操作,例如旋转、翻转、ROI(感兴趣区域)缩放和平移。

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

引言

这是一个简单的查看器应用程序,允许您对图像执行基本操作,例如旋转、翻转、ROI(感兴趣区域)缩放和平移。它提供了一个强大的 Matrix 类使用示例,以及实现非常规窗体外观的方法。使用鼠标中键实现了一个简单的窗口化方法(适用于灰度图像)。

使用代码

有趣的代码基于 DisplayPort 类,该类充当视口。还开发了一种命令机制,允许多个 DisplayPort 协同与用户交互。添加新的行为,例如在图像上方显示和设计图形,非常容易。请参阅 DisplayLinkRind 类,它是一个简单的文本叠加管理器。

要将 DisplayPort 添加到 WindowsForm,只需添加如下成员并链接 MouseDown 事件

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

    this.m_DisplayPort = new DisplayPort();

    InitializeComponent();

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

            ...

然后将控件添加到窗体

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});

            ...

将图像添加到 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);
    }
}
            ...

链接菜单列表事件

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));
    

关注点

主要困难在于创建基本的旋转/翻转例程来管理坐标转换器。我发现的关于使用 GDI+ 的唯一限制是每像素 16 位格式,该格式未实现,因此不适用于此类图像。

历史

版本 1.0 是首次发布。

© . All rights reserved.