• 大小: 821KB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2021-05-04
  • 语言: C/C++
  • 标签: MFC  vc  图像  

资源简介

用vc编程基于MFC的图像处理。可以实现图片基本的处理。如二值化,放缩,平移,锐化……图像只能打开BMP格式的。

资源截图

代码片段和文件信息

// cdib.cpp
// new version for WIN32
#include “stdafx.h“
#include “cdib.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_SERIAL(CDib Cobject 0);

CDib::CDib()
{
m_hFile = NULL;
m_hBitmap = NULL;
m_hPalette = NULL;
m_nBmihAlloc = m_nImageAlloc = noAlloc;
Empty();
}

CDib::CDib(CSize size int nBitCount)
{
m_hFile = NULL;
m_hBitmap = NULL;
m_hPalette = NULL;
m_nBmihAlloc = m_nImageAlloc = noAlloc;
Empty();
ComputePaletteSize(nBitCount);
m_lpBMIH = (LPBITMAPINFOHEADER) new 
char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * m_nColorTableEntries];
m_nBmihAlloc = crtAlloc;
m_lpBMIH->biSize = sizeof(BITMAPINFOHEADER);
m_lpBMIH->biWidth = size.cx;
m_lpBMIH->biHeight = size.cy;
m_lpBMIH->biPlanes = 1;
m_lpBMIH->biBitCount = nBitCount;
m_lpBMIH->biCompression = BI_RGB;
m_lpBMIH->biSizeImage = 0;
m_lpBMIH->biXPelsPerMeter = 0;
m_lpBMIH->biYPelsPerMeter = 0;
m_lpBMIH->biClrUsed = m_nColorTableEntries;
m_lpBMIH->biClrImportant = m_nColorTableEntries;
ComputeMetrics();
memset(m_lpvColorTable 0 sizeof(RGBQUAD) * m_nColorTableEntries);
m_lpImage = NULL;  // no data yet
}

CDib::~CDib()
{
Empty();
}

CSize CDib::GetDimensions()
{
if(m_lpBMIH == NULL) return CSize(0 0);
return CSize((int) m_lpBMIH->biWidth (int) m_lpBMIH->biHeight);
}

BOOL CDib::AttachMapFile(const char* strPathname BOOL bShare) // for reading
{
// if we open the same file twice Windows treats it as 2 separate files
// doesn‘t work with rare BMP files where # palette entries > biClrUsed
HANDLE hFile = ::CreateFile(strPathname GENERIC_WRITE | GENERIC_READ
bShare ? FILE_SHARE_READ : 0
NULL OPEN_EXISTING FILE_ATTRIBUTE_NORMAL NULL);
ASSERT(hFile != INVALID_HANDLE_VALUE);
DWORD dwFileSize = ::GetFileSize(hFile NULL);
HANDLE hMap = ::CreateFileMapping(hFile NULL PAGE_READWRITE 0 0 NULL);
DWORD dwErr = ::GetLastError();
if(hMap == NULL) {
AfxMessageBox(“Empty bitmap file“);
return FALSE;
}
LPVOID lpvFile = ::MapViewOfFile(hMap FILE_MAP_WRITE 0 0 0); // map whole file
ASSERT(lpvFile != NULL);
if(((LPBITMAPFILEHEADER) lpvFile)->bfType != 0x4d42) {
AfxMessageBox(“Invalid bitmap file“);
DetachMapFile();
return FALSE;
}
AttachMemory((LPBYTE) lpvFile + sizeof(BITMAPFILEHEADER));
m_lpvFile = lpvFile;
m_hFile = hFile;
m_hMap = hMap;
return TRUE;
}

BOOL CDib::CopyToMapFile(const char* strPathname)
{
// copies DIB to a new file releases prior pointers
// if you previously used CreateSection the HBITMAP will be NULL (and unusable)
BITMAPFILEHEADER bmfh;
bmfh.bfType = 0x4d42;  // ‘BM‘
bmfh.bfSize = m_dwSizeImage + sizeof(BITMAPINFOHEADER) +
sizeof(RGBQUAD) * m_nColorTableEntries + sizeof(BITMAPFILEHEADER);
// meaning of bfSize open to interpretation
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;
bmfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      16396  2010-02-11 15:55  图像处理\cdib.cpp

     文件       2019  2006-04-11 17:26  图像处理\cdib.h

     文件      51066  2010-09-10 13:06  图像处理\Debug\cdib.obj

     文件        368  2010-05-11 14:57  图像处理\Debug\cdib.sbr

     文件      10527  2010-09-10 13:06  图像处理\Debug\Fangsuo.obj

     文件       1140  2010-05-11 14:57  图像处理\Debug\Fangsuo.sbr

     文件     168017  2010-04-06 22:42  图像处理\Debug\jiang.exe

     文件      23245  2010-09-10 13:06  图像处理\Debug\jiang.obj

     文件     607232  2010-04-06 22:42  图像处理\Debug\jiang.pdb

     文件       8964  2010-04-03 16:36  图像处理\Debug\jiang.res

     文件       1138  2010-05-11 14:57  图像处理\Debug\jiang.sbr

     文件      83025  2010-09-10 13:06  图像处理\Debug\jiangDoc.obj

     文件       1141  2010-05-11 14:57  图像处理\Debug\jiangDoc.sbr

     文件      21380  2010-09-11 13:19  图像处理\Debug\jiangView.obj

     文件       1142  2010-05-11 14:57  图像处理\Debug\jiangView.sbr

     文件      10586  2010-04-27 16:54  图像处理\Debug\labBiZhong.obj

     文件          0  2010-04-27 16:54  图像处理\Debug\labBiZhong.sbr

     文件      20511  2010-09-10 14:16  图像处理\Debug\MainFrm.obj

     文件       1140  2010-05-11 14:57  图像处理\Debug\MainFrm.sbr

     文件      10527  2010-09-10 13:06  图像处理\Debug\Pingyi.obj

     文件       1139  2010-05-11 14:57  图像处理\Debug\Pingyi.sbr

     文件        398  2010-09-11 14:39  图像处理\Debug\scbarg.sbr

     文件     105735  2010-04-06 20:23  图像处理\Debug\StdAfx.obj

     文件    1371817  2010-04-06 20:23  图像处理\Debug\StdAfx.sbr

     文件      12711  2010-09-10 13:06  图像处理\Debug\tongdao.obj

     文件       1140  2010-05-11 14:57  图像处理\Debug\tongdao.sbr

     文件     389120  2010-05-11 14:57  图像处理\Debug\vc60.pdb

     文件      12756  2010-09-10 13:06  图像处理\Debug\Yu.obj

     文件       1135  2010-05-11 14:57  图像处理\Debug\Yu.sbr

     文件        911  2010-02-03 12:43  图像处理\Fangsuo.cpp

............此处省略39个文件信息

评论

共有 条评论