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

📄 bmp_readview.cpp

📁 用windows画笔生成BMP文件f(x,y),图象宽为W
💻 CPP
字号:
// BMP_READView.cpp : implementation of the CBMP_READView class
//

#include "stdafx.h"
#include "BMP_READ.h"

#include "BMP_READDoc.h"
#include "BMP_READView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBMP_READView

IMPLEMENT_DYNCREATE(CBMP_READView, CView)

BEGIN_MESSAGE_MAP(CBMP_READView, CView)
	//{{AFX_MSG_MAP(CBMP_READView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBMP_READView construction/destruction

CBMP_READView::CBMP_READView()
{
	// TODO: add construction code here

}

CBMP_READView::~CBMP_READView()
{
}

BOOL CBMP_READView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBMP_READView drawing

void CBMP_READView::OnDraw(CDC* pDC)
{
	CBMP_READDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CFile cf;
	CString				TransValue("未命名.bmp");
	BITMAPFILEHEADER	bmfh;
	BITMAPINFOHEADER	bmih;
	RGBTRIPLE*				rgb;
	if (!cf.Open(TransValue,CFile::modeRead/*,&e*/))
	{
		MessageBox("Can not open the file!","Open File");
		return;
	}
	cf.SeekToBegin();
	cf.Read(&bmfh,sizeof(BITMAPFILEHEADER));//读取文件头
	cf.Read(&bmih,sizeof(BITMAPINFOHEADER));//读取文件信息头
	rgb=new RGBTRIPLE[bmih.biWidth*bmih.biHeight];
	cf.SeekToBegin();
	cf.Seek(54,CFile::begin);
	//读取文件数据

	if(cf.GetLength()>64*1024)
	{
		cf.ReadHuge(rgb,bmih.biWidth*bmih.biHeight*3);
	}
	else
	{
		cf.Read(rgb,bmih.biWidth*bmih.biHeight);
	}
	//在屏幕上打点显示图像
for(int i=0;i<bmih.biHeight;i++)
	{
		for(int j=0;j<bmih.biWidth;j++)
		{
			pDC->SetPixel(j,bmih.biHeight-i,RGB(rgb[i*bmih.biWidth+j].rgbtRed,rgb[i*bmih.biWidth+j].rgbtGreen,rgb[i*bmih.biWidth+j].rgbtBlue));
		}    
	}
bmih.biHeight+=20;
bmih.biWidth+=20;

	for(int m=bmih.biHeight-20;m<bmih.biHeight;m++)
	{
		for(int n=0;n<bmih.biWidth;n++)
		{
			pDC->SetPixel(n,bmih.biHeight-m,00);
		}    
	}

    for(int mm=bmih.biWidth-20;mm<bmih.biWidth;mm++)
	{
		for(int nn=0;nn<bmih.biWidth;nn++)
		{
			pDC->SetPixel(mm,bmih.biHeight-nn,00);
		}    
	}
    

    
    


	cf.Close();//关闭文件
delete rgb;//释放内存
}



/////////////////////////////////////////////////////////////////////////////
// CBMP_READView printing

BOOL CBMP_READView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBMP_READView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CBMP_READView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CBMP_READView diagnostics

#ifdef _DEBUG
void CBMP_READView::AssertValid() const
{
	CView::AssertValid();
}

void CBMP_READView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CBMP_READDoc* CBMP_READView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBMP_READDoc)));
	return (CBMP_READDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBMP_READView message handlers

⌨️ 快捷键说明

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