📄 imglib.cpp
字号:
// ImgLib.cpp: implementation of the CImgLib class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ImgLib.h"
#include "ToolKit.h"
#include "ItemKey.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
XMRArray<BitMapCls> CBMPLib::m_arBitMapCls;
CBMPLib::CBMPLib()
{
}
CBMPLib::~CBMPLib()
{
}
char* CBMPLib::LoadBMP(char *filename, BITMAPINFOHEADER *bmpInfo)
{
FILE *file = fopen(filename, "rb");
if (!file)
{
return NULL;
}
BITMAPFILEHEADER bmpFile;
// 从一个流中读数据
fread(&bmpFile,sizeof(BITMAPFILEHEADER), 1, file);
if (bmpFile.bfType != 0x4D42)
{
fclose(file);
return NULL;
}
fread(bmpInfo, sizeof(BITMAPINFOHEADER), 1, file);
// 重定位流上的文件指针
fseek(file, bmpFile.bfOffBits, SEEK_SET);
char *bmpImage = new char[bmpInfo->biSizeImage];
if (!bmpImage)
{
delete[] bmpImage;
fclose(file);
return NULL;
}
fread(bmpImage, 1, bmpInfo->biSizeImage, file);
if (!bmpImage)
{
delete[] bmpImage;
bmpImage = NULL;
fclose(file);
return NULL;
}
fclose(file);
return bmpImage;
}
void CBMPLib::LoadBmp(char* strFilePathName,HBITMAP &hBitMap)
{
BITMAPINFOHEADER bmpInfo;
char *bmpImage = CBMPLib::LoadBMP(strFilePathName, &bmpInfo);
if (!bmpImage)
{
return ;
}
BITMAPINFO dibInfo;
dibInfo.bmiHeader = bmpInfo;
dibInfo.bmiColors[0].rgbBlue = 0;
dibInfo.bmiColors[0].rgbGreen = 0;
dibInfo.bmiColors[0].rgbRed = 0;
dibInfo.bmiColors[0].rgbReserved = 0;
HDC hMemDC = GetDC(NULL);
void *pBuffer;
hBitMap = CreateDIBSection(hMemDC,
(const BITMAPINFO*)&dibInfo, DIB_RGB_COLORS, (void**)&pBuffer, NULL, 0);
CopyMemory(pBuffer, bmpImage, bmpInfo.biSizeImage);
delete[] bmpImage;
bmpImage = NULL;
if (hMemDC)
{
ReleaseDC(NULL, hMemDC);
}
}
void CBMPLib::LoadMap(CString strName,HBITMAP &hBitMap)
{
strName = ItemKey::RES_FOLDER + strName;
//static XMRArray<BitMapCls> arBitMapCls;
int nSize = m_arBitMapCls.GetSize();
for (int i = 0; i < nSize; i++)
{
if (m_arBitMapCls.GetAt(i).m_strKey == strName)
{
hBitMap = m_arBitMapCls.GetAt(i).m_HBITMAP;
return;
}
}
BitMapCls bitMapCls;
bitMapCls.m_strKey = strName;
CString strBmpPath, strAppPath;
ToolKit::GetAppPath(strAppPath);
strBmpPath.Format("%s%s", strAppPath, strName);
char* chBmpPath = strBmpPath.GetBuffer(strBmpPath.GetLength());
//装载前先清空
hBitMap = NULL;
CBMPLib::LoadBmp(chBmpPath, hBitMap);
bitMapCls.m_HBITMAP = hBitMap;
m_arBitMapCls.Add(bitMapCls);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -