// vcvDlg.cpp : implementation file
//
#include "stdio.h"
#include "stdafx.h"
#include "vcv.h"
#include "vcvDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVcvDlg dialog
CVcvDlg::CVcvDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVcvDlg::IDD, pParent)
, fpath(_T(""))
{
//{{AFX_DATA_INIT(CVcvDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVcvDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVcvDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Text(pDX, IDC_EDIT1, fpath);
}
BEGIN_MESSAGE_MAP(CVcvDlg, CDialog)
//{{AFX_MSG_MAP(CVcvDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_RBUTTONDBLCLK()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, &CVcvDlg::OnBnClickedOk)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVcvDlg message handlers
BOOL CVcvDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CVcvDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVcvDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVcvDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVcvDlg::OnRButtonDblClk(UINT nFlags, CPoint point)
{
/*#define MAX_BUF_LEN 12
unsigned char buffer[3 * MAX_BUF_LEN];
FILE *pRead, *pWrite;
pRead = (FILE*)::fopen("e:\\123.bmp", "rb");
pWrite = (FILE*)::fopen("e:\\123.txt", "wt");
if (pRead != NULL && pWrite != NULL)
{
unsigned int fileSize;
unsigned short j;
::fseek(pRead,0,SEEK_END);
fileSize = ::ftell(pRead); //取得文件的大小
::fseek(pRead,54,0);
for ( j=0; j<((fileSize - 54)/MAX_BUF_LEN/3); j++ )
{
unsigned char index;
char ret[8];
memset((char*)&buffer, 0, (MAX_BUF_LEN * 3));
::fread(&buffer, sizeof(unsigned char), (MAX_BUF_LEN * 3), pRead);
for ( index=0; index<MAX_BUF_LEN; index++ )
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned short data;
memset((char*)&ret, 0, 8);
b = ((buffer[index * 3] >> 3) & 0x1f);
g = ((buffer[index * 3 + 1] >> 2) & 0x3f);
r = ((buffer[index * 3 + 2] >> 3) & 0x1f);
data = (unsigned short)((r << 11) | (g << 5) | b) & 0xffff;
sprintf((char*)&ret, "0X%04x,", data);
::fwrite(&ret, sizeof(char), 7, pWrite);
}
::fwrite("\n", sizeof(char), 1, pWrite);
}
}
::fclose(pRead);
::fclose(pWrite);
CDialog::OnRButtonDblClk(nFlags, point);*/
}
void CVcvDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFileDialog fdlg(TRUE,_T(""),_T(""),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("图片格式(*.bmp)|*.bmp"));
if (IDOK==fdlg.DoModal ())
{
name=fdlg.GetFileTitle();
fpath=fdlg.GetPathName();
i=1;
//BITMAPINFOHEADER bmi;
BITMAPFILEHEADER bmfh;
CFile* f;
f = new CFile();
f->Open(fpath, CFile::modeRead);
f->SeekToBegin();
f->Read(&bmfh, sizeof(bmfh));
f->Read(&bmi, sizeof(bmi));
f->Close();
delete f;
UpdateData(FALSE);
}
}
void CVcvDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
if(i==1)
{
/*BITMAPINFOHEADER bmi;
BITMAPFILEHEADER bmfh;
FILE *r;
CFile* f;
f = new CFile();
f->Open(fpath, CFile::modeRead);
f->SeekToBegin();
f->Read(&bmfh, sizeof(bmfh));
f->Read(&bmi, sizeof(bmi));
f->Close();
delete f;
*/
/*r=(FILE*)::fopen(fpath,"rb");
::fseek(r,0,SEEK_SET);
::fread (&bmi,sizeof(unsigned int), sizeof(bmi),r);
::fclose(r);
*/
int len=bmi.biWidth ;
int whi=bmi.biHeight;
int hen=len/20;
#define MAX_BUF_LEN len//12
#define MAX_LEN (hen)//12
unsigned char buffer[3 * 320];
unsigned char buffer2[3 * 240];
unsigned char buffer3[3 * 240];
FILE *pRead, *pWrite;
CString fname;
fname="e:\\"+name+".txt";
pRead = (FILE*)::fopen(fpath, "rb");
pWrite = (FILE*)::fopen(fname, "wt");
if (pRead != NULL && pWrite != NULL)
{
unsigned int fileSize;
//unsigned short j;
unsigned int j;
::fseek(pRead,0,SEEK_END);
fileSize = ::ftell(pRead); //取得文件的大小
::fseek(pRead,54,0);
int t=(fileSize - 54)/MAX_BUF_LEN/3;
for ( j=t; j>0; j-- )
//for ( j=0; j<((fileSize - 54)/MAX_BUF_LEN/3); j++ ) //转换图片文件获取行数
{
unsigned char index;
char ret[8];
::fseek(pRead,(j-1)*MAX_BUF_LEN*3+54,0);
memset((char *)&buffer, 0, (MAX_BUF_LEN * 3));
::fread(&buffer, sizeof(unsigned char), (MAX_BUF_LEN * 3), pRead);
for(int i=0;i< MAX_BUF_LEN/MAX_LEN;i++)
{
for ( index=0; index<MAX_LEN/*MAX_BUF_LEN*/; index++ ) //每行的读入
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned short data;
memset((char*)&ret, 0, 8);
b = ((buffer[i*MAX_LEN*3+index * 3] >> 3) & 0x1f);
g = ((buffer[i*MAX_LEN*3+index * 3 + 1] >> 2) & 0x3f);
r = ((buff