图片显示 类

利用直方图的对话框资源IDD_HISTOGRAM,关联类文件:enum{ IDD = IDD_HISTOGRAM };
更改 开始的宏定义名称
调用:

BmpDlg *bmpdlg = new BmpDlg();
bmpdlg->Init(gray,myBmp.GetBmpWidth(),myBmp.GetHeight());
bmpdlg->Create(IDD_HISTOGRAM,this);
bmpdlg->SetWindowText(myBmp.GetBmpName());
bmpdlg->ShowWindow(SW_SHOW);

或者:

BmpDlg *bmpdlg = new BmpDlg();
bmpdlg->Init(NULL,myBmp.GetBmpWidth(),myBmp.GetHeight()); bmpdlg->Create(IDD_HISTOGRAM,this); bmpdlg->SetWindowText(myBmp.GetBmpName()); myProcess.ShowArrayToDevice(&bmpdlg->dcMemory,0,0,gray,myBmp.GetBmpWidth(),myBmp.GetHeight()); bmpdlg->ShowWindow(SW_SHOW);

或者直接利用其他函数绘制彩色图像:

BmpDlg *bmpdlg = new BmpDlg(); 
bmpdlg->Init(NULL,myBmp.GetBmpWidth(),myBmp.GetHeight()); 
bmpdlg->Create(IDD_HISTOGRAM,this);
bmpdlg->SetWindowText(myBmp.GetBmpName());
myBmp.ShowBmpToDevice(&bmpdlg->dcMemory,0,0);//在双重缓冲中绘图 
bmpdlg->ShowWindow(SW_SHOW);

完整代码

#pragma once
// Histogram.h : header file
//
#include"resource.h"
/////////////////////////////////////////////////////////////////////////////
// Histogram dialog
classBmpDlg:publicCDialog
{
public:
    voidInit(unsignedchar* array,int width,int height);
    BmpDlg(CWnd* pParent = NULL);
    CDC dcMemory;
    unsignedchar*bmp;
    unsignedchar*huidubmp;
    int width;
    int height;
    enum{ IDD = IDD_HISTOGRAM };
    protected:
    virtualvoidDoDataExchange(CDataExchange* pDX);
    protected:
    afx_msg void OnPaint();
    virtual BOOL OnInitDialog();
    DECLARE_MESSAGE_MAP()
    };
CPP
// Histogram.cpp : implementation file
//
#include"stdafx.h"
#include"BmpDlg.h"
#ifdef _DEBUG
#definenew DEBUG_NEW
#undef THIS_FILE
staticchar THIS_FILE[]= __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Histogram dialog
BmpDlg::BmpDlg(CWnd* pParent /*=NULL*/)
:CDialog(BmpDlg::IDD, pParent)
{
    bmp=NULL;
}
voidBmpDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(BmpDlg,CDialog)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Histogram message handlers
voidBmpDlg::OnPaint()
{
    CPaintDC dc(this);
    dc.BitBlt(0,0,width,height,&dcMemory,0,0,SRCCOPY);

}
BOOL BmpDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    CPaintDC dc(this);// device context for painting
    dcMemory.CreateCompatibleDC(&dc);
    CBitmap bitmap;
    bitmap.CreateCompatibleBitmap(&dc,width,height);
    dcMemory.SelectObject(&bitmap);
    if(bmp!=NULL)
    {
        for(int i=0;i<height;i++)
        for(int j=0;j<width;j++)
        {
            dcMemory.SetPixel(j,height-i,RGB(bmp[i*(width)+j],bmp[i*(width)+j],bmp[i*(width)+j]));
        }
    }
    CRect rect(0,0,width,height);
    this->MoveWindow(&rect,true);
    return TRUE
}
voidBmpDlg::Init(unsignedchar* array,int width,int height)
{
    this->width=width;
    this->height = height;
    if(array!=NULL)
    {
        bmp =newunsignedchar[width*height];
        memcpy(bmp,array,width*height*sizeof(unsignedchar));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值