convertView.cpp
上传用户:shdqsh
上传日期:2014-10-15
资源大小:103k
文件大小:7k
- // convertView.cpp : implementation of the CConvertView class
- //
- #include "stdafx.h"
- #include "convert.h"
- #include "convertDoc.h"
- #include "convertView.h"
- #include "DialogGetImg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView
- IMPLEMENT_DYNCREATE(CConvertView, CView)
- BEGIN_MESSAGE_MAP(CConvertView, CView)
- //{{AFX_MSG_MAP(CConvertView)
- ON_COMMAND(ID_IMAGE_GET, OnImageGet)
- ON_COMMAND(ID_DIGIMG_FILEOPEN, OnDigimgFileopen)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView construction/destruction
- CConvertView::CConvertView()
- {
- // TODO: add construction code here
- }
- CConvertView::~CConvertView()
- {
- }
- BOOL CConvertView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView drawing
- void CConvertView::OnDraw(CDC* pDC)
- {
- CConvertDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
-
- unsigned char gray;
- int i,j;
- int row=pDoc->myImage.m_ImageHeight;//......
- int col=pDoc->myImage.m_ImageWidth;
- for(i=0;i<row;i++)
- for(j=0;j<col;j++)
- {
- gray=pDoc->myImage.image[i][j];
- pDC->SetPixel(j+10,i+10,RGB(gray,gray,gray));
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView printing
- BOOL CConvertView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CConvertView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CConvertView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView diagnostics
- #ifdef _DEBUG
- void CConvertView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CConvertView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CConvertDoc* CConvertView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CConvertDoc)));
- return (CConvertDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CConvertView message handlers
- //DEL BOOL CConvertView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll)
- //DEL {
- //DEL // TODO: Add your specialized code here and/or call the base class
- //DEL
- //DEL return CView::OnScroll(nScrollCode, nPos, bDoScroll);
- //DEL }
- //DEL void CConvertView::OnSize(UINT nType, int cx, int cy)
- //DEL {
- //DEL CView::OnSize(nType, cx, cy);
- //DEL
- //DEL CView::SetScrollPos(setPageSize
- //DEL }
- //DEL void CConvertView::OnInitialUpdate()
- //DEL {
- //DEL // CScrollView::OnInitialUpdate();
- //DEL
- //DEL CSize sizeTotal(800,1050);
- //DEL CSize sizePage(sizeTotal.cx/2,sizeTotal.cy/2);
- //DEL CSize sizeLine(sizeTotal.cx/50,sizeTotal.cy/50);
- //DEL // SetScrollSizes(MM_LOENGLISH,sizeTotal,sizePage,sizeLine);
- //DEL // TODO: Add your specialized code here and/or call the base class
- //DEL // SetScrollRange(200,800,13200,false);
- //DEL SetTotalSize(6000);
- //DEL
- //DEL }
- void CConvertView::SaveBmpFile(int iWidth, int iHeight, unsigned char** pImageData,CFile file)
- {
- int temp=((iWidth+3)/4)*4; //补零后的图像宽度
- int filelength = iHeight*temp+1078+2; //文件长度 ,注意末尾要补2个0
- BYTE * toSaveFileData=new BYTE [filelength];
- //写文件头(54字节)
- toSaveFileData[0]='B'; // image type.
- toSaveFileData[1]='M';
- toSaveFileData[2]=(BYTE) ((filelength<<24)>>24); //file size
- toSaveFileData[3]=(BYTE) ((filelength<<16)>>24);
- toSaveFileData[4]=(BYTE) ((filelength<<8)>>24);
- toSaveFileData[5]=(BYTE) (filelength>>24);
- toSaveFileData[6]=toSaveFileData[7]=toSaveFileData[8]=toSaveFileData[9]=0;
- toSaveFileData[10]=54; //位图阵列相对于文件头的偏移量1078
- toSaveFileData[11]=4;
- toSaveFileData[12]=toSaveFileData[13]=0;
- toSaveFileData[14]=40; //位图文件头标bitmapinfoheader的大小
- toSaveFileData[15]=toSaveFileData[16]=toSaveFileData[17]=0;
- toSaveFileData[18]=(BYTE) ((iWidth<<24)>>24); //image width
- toSaveFileData[19]=(BYTE) ((iWidth<<16)>>24);
- toSaveFileData[20]=(BYTE) ((iWidth<<8)>>24);
- toSaveFileData[21]=(BYTE) (iWidth>>24);
- toSaveFileData[22]=(BYTE) ((iHeight<<24)>>24); //image height
- toSaveFileData[23]=(BYTE) ((iHeight<<16)>>24);
- toSaveFileData[24]=(BYTE) ((iHeight<<8)>>24);
- toSaveFileData[25]=(BYTE) (iWidth>>24);
- toSaveFileData[26]=1; //must be 1
- toSaveFileData[27]=0;
- toSaveFileData[28]=8; //bits per pixel,must be 1,4 8,or24
- toSaveFileData[29]=0;
- toSaveFileData[30]=0; //压缩方式,0表示未压缩,1表示每个象素8位表示
- toSaveFileData[31]=toSaveFileData[32]=toSaveFileData[33]=0;
- toSaveFileData[34]=toSaveFileData[35]=toSaveFileData[36]=toSaveFileData[37]=0;//压缩图象大小
- toSaveFileData[38]=80; //水平分辨率
- toSaveFileData[39]=toSaveFileData[40]=toSaveFileData[41]=0;
- toSaveFileData[42]=80; //垂直分辨率
- toSaveFileData[43]=toSaveFileData[44]=toSaveFileData[45]=0;
- toSaveFileData[46]=toSaveFileData[47]=toSaveFileData[48]=toSaveFileData[49]=0;//color number used
- toSaveFileData[50]=toSaveFileData[51]=toSaveFileData[52]=toSaveFileData[53]=0;//important color,if all color are important,it should be set 0
- //写颜色表(1024字节)
- for(int i=0;i<256;i++)
- {
- toSaveFileData[54+4*i]=(BYTE) i ;
- toSaveFileData[54+4*i+1]=(BYTE) i ;
- toSaveFileData[54+4*i+2]=(BYTE) i;
- toSaveFileData[54+4*i+3]=0;
- }
- //写图象矩阵
- for(i=0;i<iHeight;i++)
- {
- for(int j = 0; j < iWidth; j++)
- toSaveFileData[1078 + i * temp + j] = pImageData[i][j];
- for(j = 0; j < temp - iWidth; j++)
- toSaveFileData[1078 + i * temp + iWidth + j] = 0; //补0操作
- }
- toSaveFileData[1078 + iHeight * temp+ 1]= toSaveFileData[1078 + iHeight * temp +2] = 0;
-
- file.Write((void*)toSaveFileData,filelength);
- if(toSaveFileData != NULL)
- {
- delete [] toSaveFileData;
- toSaveFileData = NULL;
- }
- return;
- }
- void CConvertView::OnImageGet()
- {
- // CDialogGetImg getImgDlg;
- // getImgDlg.m_oriHeight=myImage.m_ImageHeight;
- // getImgDlg.m_oriWidth=myImage.m_ImageWidth;
-
- }
- void CConvertView::OnDigimgFileopen()
- {
-
- }