⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showbmp.cpp

📁 madaline网络是神经网络中一类重要的类型
💻 CPP
字号:
// ShowBmp.cpp : implementation file
//

#include "stdafx.h"
#include "E1109_1.h"
#include "ShowBmp.h"
#include "E1109_1Doc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShowBmp dialog
 RECT rect;
 
//CPoint st,et;
CShowBmp::CShowBmp(CWnd* pParent /*=NULL*/)
	: CDialog(CShowBmp::IDD, pParent)
{    m_pDib=new CDib;
	//{{AFX_DATA_INIT(CShowBmp)
	m_show = 0;
	//}}AFX_DATA_INIT
}


void CShowBmp::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowBmp)
	DDX_Text(pDX, IDC_EDIT1, m_show);
	DDV_MinMaxInt(pDX, m_show, 0, 400);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShowBmp, CDialog)
	//{{AFX_MSG_MAP(CShowBmp)
	ON_BN_CLICKED(IDC_SHOWBMP, OnShowbmp)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_SHUAXIN, OnShuaxin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowBmp message handlers

void CShowBmp::OnShowbmp() 
{
	// TODO: Add your control notification handler code here
		CFileDialog  dlg(TRUE,"bmp","*.bmp");
	if(dlg.DoModal()==IDOK)
	{
		CFile file;
		CString strPathName;
		strPathName=dlg.GetPathName();
		if(!file.Open(strPathName,CFile::modeRead|CFile::shareDenyWrite))
		{
			return;
		}
	
		if(!m_pDib->Read(&file))
		{
      
			EndWaitCursor();
			m_pDib->Empty();
			return;
		}
	}
	this->Invalidate();

    CPaintDC dc(this);

	//获取显示图象的标签
	CWnd*pWnd=GetDlgItem(IDC_PICTURE1);

	//获取设备上下文
	CDC*pDC=pWnd->GetDC();
	pWnd->Invalidate();
	pWnd->UpdateWindow();
    
	//显示图象
	m_pDib->Draw(pDC,CPoint(0,0),CSize(250,250));
	m_Width=m_pDib->GetDimensions().cx;
	m_Height=m_pDib->GetDimensions().cy;

	
	m_pData=m_pDib->m_lpImage;    //获取图象数据区指针
   
	float widethbizhi,heightbizhi;
	widethbizhi=(float)250/140;
	heightbizhi=(float)250/152;

}

void CShowBmp::OnButton2() 
{   int i,j;
	for(j=0;j<m_Height;j++)
		for(i=0;i<m_Width;i++)
		{
	         BYTE*phyRed=m_pData++;
             BYTE*phyGreen=m_pData++;
	         BYTE*phyBlue=m_pData++;
	         int red=*phyRed;
	         int green=*phyGreen;
	         int blue=*phyBlue;
             int gray=0;
		     if(red>green) gray=red;
			 else gray=green;
			 if(gray<blue) gray=blue;
			 *phyRed=gray;
			 *phyGreen=gray;
			 *phyBlue=gray;
		}
	// TODO: Add your control notification handler code here
	CWnd*pWnd=GetDlgItem(IDC_PICTURE2);

	//获取设备上下文
	CDC*pDC=pWnd->GetDC();
	pWnd->Invalidate();
	pWnd->UpdateWindow();
    
	//显示图象
	m_pDib->Draw(pDC,CPoint(75,70),m_pDib->GetDimensions());

}

void CShowBmp::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
}

void CShowBmp::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	rect.right=point.x;
	rect.bottom=point.y;
   UpdateData(false);
	m_show=point.x;
    

	

	
	CDialog::OnMouseMove(nFlags, point);
}

void CShowBmp::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
   
    rect.left=point.x;
	rect.top=point.y;

	m_pData=m_pDib->m_lpImage;  //********将m_pData重新指向图象的起始点amend at_1111
	
	CDialog::OnLButtonDown(nFlags, point);
}

void CShowBmp::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
     	
//
    
	CDialog::OnLButtonDblClk(nFlags, point);
}

void CShowBmp::OnLButtonUp(UINT nFlags, CPoint point) 
{  int OldEndx,OldEndy,NewStartx,NewStarty;//********求鼠标所选的框形在原图象中的坐标位置
	float widethbizhi,heightbizhi;
	widethbizhi=(float)250/140;
	heightbizhi=(float)250/152;
	NewStartx=(int)rect.left/widethbizhi;
    NewStarty=(int)rect.top/heightbizhi;
    OldEndx=(int)rect.right/widethbizhi;
	OldEndy=(int)rect.bottom/heightbizhi;
    int RectWidth=RECTWIDTH(NewStartx,OldEndx);//******求矩形的宽
    int RectHeight=RECTHEIGHT(NewStarty,OldEndy);//****求矩形的高
    int sum=RectWidth*RectHeight*3;
 
	int Save[20000];//*********矩形框的大小要受到数组的限制的!!!!
	int i,j,l;
	int k=0;
	for(k=0;k<20000;k++)//********初始化数组Save[] amend at_1111
	{
		Save[k]=0;
	}
	
//   int n;
//	n=RectWidth*RectHeight;
//	dongtaifenpei(n);//********调用dongtaifenpei()函数给动态地分配数组的大小

     k=0;
	 for(i=0;i<((NewStarty-1)*m_Width+NewStartx)*3;i++)//********将指针移动到矩形的坐上角点
	 {   
		 m_pData++;
		 
	 }	 
    int count;
 
	for(j=NewStarty;j<OldEndy;j++)//************取矩形框的像素值
	{
		for(i=NewStartx;i<OldEndx;i++)//********取每一行的像素值并保存到Save[]数组中
			{   BYTE*phyRed=m_pData++;
		        Save[k]=*phyRed;
				
				k=k+1;
			}
	
	    for(l=0;l<(m_Width-RectWidth)*3;l++)//*******将指针移动到矩形框的下一行中
		{
			m_pData++;
			
		}
		
	}

	CClientDC dc(this);
    
	dc.SelectStockObject(WHITE_PEN);//******选择框边为白线;或(黑线BLACK_PEN)
	                                 
	
if((rect.left>=30)&&(rect.top>=30)&&(rect.right<=280)&&(rect.bottom<=280))
	{  
	  
      dc.MoveTo(rect.left,rect.top);
	    dc.LineTo(rect.left,rect.bottom);
		
       dc.MoveTo(rect.left,rect.bottom);
	    dc.LineTo(rect.right,rect.bottom);

		dc.MoveTo(rect.right,rect.bottom);
	    dc.LineTo(rect.right,rect.top);

		dc.MoveTo(rect.right,rect.top);
	    dc.LineTo(rect.left,rect.top);
    }
    
	// TODO: Add your message handler code here and/or call default

	CDialog::OnLButtonUp(nFlags, point);
}

void CShowBmp::OnShuaxin() 
{ 
	// TODO: Add your control notification handler code here
   //OnEraseBorder(1,dc);//删除按钮边界
	
}

void CShowBmp::dongtaifenpei(int n)
{
//Sa=(int *)malloc(n*sizeof(int)); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -