学而不思则罔,思而不学则殆

有其事必有其理, 有其理必有其事

  IT博客 :: 首页 :: 联系 :: 聚合  :: 管理
  85 Posts :: 12 Stories :: 47 Comments :: 0 Trackbacks

#pragma once

 


typedef struct _VC_BITMAPINFO {
 BITMAPINFOHEADER    bmiHeader;
 //union {
 // VC_RGB565_MASKS  rgbMasks;
 DWORD    bwPalette[ 256 ];
 //};
} VC_BITMAPINFO, *PVC_BITMAPINFO;


// CIRImageView

class CIRImageView : public CStatic
{
 DECLARE_DYNAMIC(CIRImageView)

public:
 CIRImageView();
 virtual ~CIRImageView();

private:
 HBITMAP   hStillBitmap ;
 PUCHAR   pStillImageData;
 PUCHAR   p_tmpMem  ;

 VC_BITMAPINFO bmiStill  ;
protected:
 DECLARE_MESSAGE_MAP()
public:

 int UpdateIrisImage(BYTE* pData);
 int ClearIrisImage();
 afx_msg void OnPaint();
 int InitBmpStruct(void);


};


 

// IRImageView.cpp : 实现文件
//

#include "stdafx.h"
#include "IRImageView.h"
#include "applib.h"

//////////////////////////////////////////////////////////////////////////

#define ES_RZ_WIDTH 2560
#define ES_RZ_HIGH  800

//#define ES_RZ_WIDTH 640
//#define ES_RZ_HIGH  480

//////////////////////////////////////////////////////////////////////////
// CIRImageView

IMPLEMENT_DYNAMIC(CIRImageView, CStatic)

CIRImageView::CIRImageView()
{
 hStillBitmap =  NULL ;
 p_tmpMem  = NULL  ;
 InitBmpStruct() ;
}

CIRImageView::~CIRImageView()
{
 if ( hStillBitmap != NULL )
 {
  DeleteObject( hStillBitmap );
  hStillBitmap = NULL;
 }
}


BEGIN_MESSAGE_MAP(CIRImageView, CStatic)
 ON_WM_PAINT()
END_MESSAGE_MAP()

// CIRImageView 消息处理程序

 


int CIRImageView::ClearIrisImage()
{
 memset(pStillImageData , 0 ,  ES_RZ_WIDTH * ES_RZ_HIGH ) ;
 Invalidate(true) ;
 return 0;
}

int CIRImageView::UpdateIrisImage(BYTE* pData)
{
 int ImageHeight = ES_RZ_WIDTH;
 int ImageWidth = ES_RZ_HIGH;
 //For test preview update

 int j=0 ; 
 for(int iY = (INT32)(ImageHeight - 1); iY >= 0; iY--)
 {                               
  for(int iX = 0; iX < ImageWidth; iX++)
  {                              
   pStillImageData[( ( ImageHeight -1 - iY ) * ImageWidth) +  ( ImageWidth -1 - iX) ] = (UINT8)pData[(iY * ImageWidth) + iX] ;
  }  
 }

 Invalidate(FALSE) ;
 return 0;
}

void CIRImageView::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 // TODO: 在此处添加消息处理程序代码
 // 不为绘图消息调用 CStatic::OnPaint()

 int   imageWidth;
 int   imageHeight;
 RECT    rect ,win ;
 ::GetClientRect(m_hWnd, &rect);

 imageWidth = ES_RZ_WIDTH;
 imageHeight = ES_RZ_HIGH;

 int   i   =   SetStretchBltMode(dc.m_hDC,COLORONCOLOR);

 StretchDIBits( dc.m_hDC,
 0,0,rect.right, rect.bottom,
 0,0,imageWidth, (UINT)imageHeight,
 pStillImageData,
 (BITMAPINFO*)&bmiStill,  DIB_RGB_COLORS , SRCCOPY
 );
}

int CIRImageView::InitBmpStruct(void)
{
 // create the still dib
 bmiStill.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
 bmiStill.bmiHeader.biWidth = ES_RZ_WIDTH;
 bmiStill.bmiHeader.biHeight = ES_RZ_HIGH;
 bmiStill.bmiHeader.biPlanes = 1;
 bmiStill.bmiHeader.biSizeImage = 0;
 bmiStill.bmiHeader.biXPelsPerMeter = 0;
 bmiStill.bmiHeader.biYPelsPerMeter = 0;
 bmiStill.bmiHeader.biClrUsed = 0;
 bmiStill.bmiHeader.biClrImportant = 0; 

 bmiStill.bmiHeader.biBitCount = 8;
 bmiStill.bmiHeader.biCompression = BI_RGB;

 int  stillImageSize = ES_RZ_WIDTH  * ES_RZ_HIGH;

 // initialize the black and white palette
 for ( int i=0; i < 256; i++ ) {
  bmiStill.bwPalette[i] = i | ( i << 8 ) | ( i << 16 );
 }

 if (NULL == hStillBitmap)
 {
  HDC hDc  = ::GetDC( m_hWnd );
  hStillBitmap = CreateDIBSection( hDc, (LPBITMAPINFO) &bmiStill, DIB_RGB_COLORS, (PVOID *) &pStillImageData, NULL, 0 );
 }
 
 return 0;
}

posted on 2011-12-26 11:15 易道 阅读(1427) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。