图片显示 类

来源:互联网 发布:php 大端小端 转换 编辑:程序博客网 时间:2024/06/11 22:48

利用直方图的对话框资源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 dialogclassBmpDlg: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_FILEstaticchar THIS_FILE[]= __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// Histogram dialogBmpDlg::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 handlersvoidBmpDlg::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
原创粉丝点击