convertView.cpp
上传用户:shdqsh
上传日期:2014-10-15
资源大小:103k
文件大小:7k
源码类别:

图形图像处理

开发平台:

Visual C++

  1. // convertView.cpp : implementation of the CConvertView class
  2. //
  3. #include "stdafx.h"
  4. #include "convert.h"
  5. #include "convertDoc.h"
  6. #include "convertView.h"
  7. #include "DialogGetImg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CConvertView
  15. IMPLEMENT_DYNCREATE(CConvertView, CView)
  16. BEGIN_MESSAGE_MAP(CConvertView, CView)
  17. //{{AFX_MSG_MAP(CConvertView)
  18. ON_COMMAND(ID_IMAGE_GET, OnImageGet)
  19. ON_COMMAND(ID_DIGIMG_FILEOPEN, OnDigimgFileopen)
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CConvertView construction/destruction
  28. CConvertView::CConvertView()
  29. {
  30. // TODO: add construction code here
  31. }
  32. CConvertView::~CConvertView()
  33. {
  34. }
  35. BOOL CConvertView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. // TODO: Modify the Window class or styles here by modifying
  38. //  the CREATESTRUCT cs
  39. return CView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CConvertView drawing
  43. void CConvertView::OnDraw(CDC* pDC)
  44. {
  45. CConvertDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. // TODO: add draw code for native data here
  48.     
  49. unsigned char gray;
  50.     int i,j;
  51.     int row=pDoc->myImage.m_ImageHeight;//......
  52. int col=pDoc->myImage.m_ImageWidth;
  53.     for(i=0;i<row;i++)
  54.    for(j=0;j<col;j++)
  55.    {
  56.    gray=pDoc->myImage.image[i][j];
  57.    pDC->SetPixel(j+10,i+10,RGB(gray,gray,gray));
  58.    }
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CConvertView printing
  62. BOOL CConvertView::OnPreparePrinting(CPrintInfo* pInfo)
  63. {
  64. // default preparation
  65. return DoPreparePrinting(pInfo);
  66. }
  67. void CConvertView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  68. {
  69. // TODO: add extra initialization before printing
  70. }
  71. void CConvertView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  72. {
  73. // TODO: add cleanup after printing
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CConvertView diagnostics
  77. #ifdef _DEBUG
  78. void CConvertView::AssertValid() const
  79. {
  80. CView::AssertValid();
  81. }
  82. void CConvertView::Dump(CDumpContext& dc) const
  83. {
  84. CView::Dump(dc);
  85. }
  86. CConvertDoc* CConvertView::GetDocument() // non-debug version is inline
  87. {
  88. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CConvertDoc)));
  89. return (CConvertDoc*)m_pDocument;
  90. }
  91. #endif //_DEBUG
  92. /////////////////////////////////////////////////////////////////////////////
  93. // CConvertView message handlers
  94. //DEL BOOL CConvertView::OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll) 
  95. //DEL {
  96. //DEL  // TODO: Add your specialized code here and/or call the base class
  97. //DEL 
  98. //DEL  return CView::OnScroll(nScrollCode, nPos, bDoScroll);
  99. //DEL }
  100. //DEL void CConvertView::OnSize(UINT nType, int cx, int cy) 
  101. //DEL {
  102. //DEL  CView::OnSize(nType, cx, cy);
  103. //DEL 
  104. //DEL  CView::SetScrollPos(setPageSize
  105. //DEL }
  106. //DEL void CConvertView::OnInitialUpdate() 
  107. //DEL {
  108. //DEL // CScrollView::OnInitialUpdate();
  109. //DEL 
  110. //DEL  CSize sizeTotal(800,1050);
  111. //DEL  CSize sizePage(sizeTotal.cx/2,sizeTotal.cy/2);
  112. //DEL  CSize sizeLine(sizeTotal.cx/50,sizeTotal.cy/50);
  113. //DEL // SetScrollSizes(MM_LOENGLISH,sizeTotal,sizePage,sizeLine);
  114. //DEL  // TODO: Add your specialized code here and/or call the base class
  115. //DEL // SetScrollRange(200,800,13200,false);
  116. //DEL  SetTotalSize(6000);
  117. //DEL 
  118. //DEL }
  119. void  CConvertView::SaveBmpFile(int iWidth, int iHeight, unsigned char** pImageData,CFile file)
  120. {
  121. int temp=((iWidth+3)/4)*4;               //补零后的图像宽度
  122.         int filelength = iHeight*temp+1078+2;    //文件长度 ,注意末尾要补2个0
  123.         BYTE * toSaveFileData=new BYTE [filelength];
  124.         //写文件头(54字节)
  125.         toSaveFileData[0]='B';                   // image type.
  126.         toSaveFileData[1]='M';
  127.         toSaveFileData[2]=(BYTE) ((filelength<<24)>>24);  //file size
  128.         toSaveFileData[3]=(BYTE) ((filelength<<16)>>24);
  129.         toSaveFileData[4]=(BYTE) ((filelength<<8)>>24);
  130.         toSaveFileData[5]=(BYTE) (filelength>>24);
  131.         toSaveFileData[6]=toSaveFileData[7]=toSaveFileData[8]=toSaveFileData[9]=0;
  132.         toSaveFileData[10]=54;                   //位图阵列相对于文件头的偏移量1078
  133.         toSaveFileData[11]=4;
  134.         toSaveFileData[12]=toSaveFileData[13]=0;
  135.         toSaveFileData[14]=40;                   //位图文件头标bitmapinfoheader的大小
  136.         toSaveFileData[15]=toSaveFileData[16]=toSaveFileData[17]=0;
  137.         toSaveFileData[18]=(BYTE) ((iWidth<<24)>>24);      //image width
  138.         toSaveFileData[19]=(BYTE) ((iWidth<<16)>>24);
  139.         toSaveFileData[20]=(BYTE) ((iWidth<<8)>>24);
  140.         toSaveFileData[21]=(BYTE) (iWidth>>24);
  141.         toSaveFileData[22]=(BYTE) ((iHeight<<24)>>24);     //image height
  142.         toSaveFileData[23]=(BYTE) ((iHeight<<16)>>24);
  143.         toSaveFileData[24]=(BYTE) ((iHeight<<8)>>24);
  144.         toSaveFileData[25]=(BYTE) (iWidth>>24);
  145.         toSaveFileData[26]=1;                    //must be 1
  146.         toSaveFileData[27]=0;
  147.         toSaveFileData[28]=8;                    //bits per pixel,must be 1,4 8,or24
  148.         toSaveFileData[29]=0;
  149.         toSaveFileData[30]=0;                    //压缩方式,0表示未压缩,1表示每个象素8位表示
  150.         toSaveFileData[31]=toSaveFileData[32]=toSaveFileData[33]=0;
  151.         toSaveFileData[34]=toSaveFileData[35]=toSaveFileData[36]=toSaveFileData[37]=0;//压缩图象大小
  152.         toSaveFileData[38]=80;                   //水平分辨率
  153.         toSaveFileData[39]=toSaveFileData[40]=toSaveFileData[41]=0;
  154.         toSaveFileData[42]=80;                   //垂直分辨率
  155.         toSaveFileData[43]=toSaveFileData[44]=toSaveFileData[45]=0;
  156.         toSaveFileData[46]=toSaveFileData[47]=toSaveFileData[48]=toSaveFileData[49]=0;//color number used
  157.         toSaveFileData[50]=toSaveFileData[51]=toSaveFileData[52]=toSaveFileData[53]=0;//important color,if all color are important,it should be set 0
  158.         //写颜色表(1024字节)
  159.         for(int i=0;i<256;i++)
  160.         {
  161.               toSaveFileData[54+4*i]=(BYTE) i ;
  162.               toSaveFileData[54+4*i+1]=(BYTE) i ;
  163.               toSaveFileData[54+4*i+2]=(BYTE) i;
  164.               toSaveFileData[54+4*i+3]=0;
  165.         }
  166.         //写图象矩阵
  167.        for(i=0;i<iHeight;i++)
  168.         {
  169.             for(int j = 0; j < iWidth; j++)
  170.                toSaveFileData[1078 + i * temp + j] = pImageData[i][j];
  171.             for(j = 0; j < temp - iWidth; j++)
  172.                toSaveFileData[1078 + i * temp + iWidth + j] = 0; //补0操作
  173.         }
  174.          toSaveFileData[1078 + iHeight *  temp+ 1]= toSaveFileData[1078 + iHeight * temp +2] = 0;
  175.          
  176. file.Write((void*)toSaveFileData,filelength);
  177.     if(toSaveFileData != NULL)
  178.     {
  179.         delete [] toSaveFileData;
  180.         toSaveFileData = NULL;
  181.     }
  182.     return;
  183. }
  184. void CConvertView::OnImageGet() 
  185. {
  186.  //   CDialogGetImg getImgDlg;
  187. //    getImgDlg.m_oriHeight=myImage.m_ImageHeight;
  188.  //   getImgDlg.m_oriWidth=myImage.m_ImageWidth;
  189. }
  190. void CConvertView::OnDigimgFileopen() 
  191. {
  192.     
  193. }