资源简介
转载自pudn,仅做交流学习用途,不得用作商业用途。
代码片段和文件信息
// DIB.cpp
#include “stdafx.h“
#include “DIB.h“
CDib::CDib()
{
m_pDib = NULL;
m_pWordData = NULL;
m_pFile = NULL;
m_pOldDibShow = NULL;
}
CDib::~CDib()
{
if( m_pDib != NULL )
delete [] m_pDib;
if( m_pWordData != NULL )
delete [] m_pWordData;
if (m_pFile != NULL)
delete [] m_pFile;
if (m_pOldDibShow != NULL)
delete [] m_pOldDibShow;
}
BOOL CDib::Load( const char *pszFilename )
{
CFile cf;
if( !cf.Open( pszFilename CFile::modeRead ) )
return( FALSE );
DWORD dwDibSize;
dwDibSize =
cf.GetLength() - sizeof( BITMAPFILEHEADER );
unsigned char *pDib;
pDib = new unsigned char [dwDibSize];
if( pDib == NULL )
return( FALSE );
BITMAPFILEHEADER BFH;
try{
if( cf.Read( &BFH sizeof( BITMAPFILEHEADER ) )
!= sizeof( BITMAPFILEHEADER ) ||
BFH.bfType != ‘MB‘ ||
cf.Read( pDib dwDibSize ) != dwDibSize ){
delete [] pDib;
return( FALSE );
}
}
catch( CFileException *e ){
e->Delete();
delete [] pDib;
return( FALSE );
}
cf.Close();
if( m_pDib != NULL )
delete m_pDib;
if (BFH.bfReserved1 != 0) //含有隐藏信息,保存其大小
{
if (BFH.bfReserved2 == 0)
embfile_size = BFH.bfReserved1;
else
embfile_size = BFH.bfReserved1 + 65535;
}
m_pDib = pDib;
m_dwDibSize = dwDibSize;
m_pBIH = (BITMAPINFOHEADER *) m_pDib;
m_pPalette =
(RGBQUAD *) &m_pDib[sizeof(BITMAPINFOHEADER)];
m_nPaletteEntries = 1 << m_pBIH->biBitCount;
if( m_pBIH->biBitCount > 8 )
m_nPaletteEntries = 0;
else if( m_pBIH->biClrUsed != 0 )
m_nPaletteEntries = m_pBIH->biClrUsed;
m_pDibBits =
&m_pDib[sizeof(BITMAPINFOHEADER)+
m_nPaletteEntries*sizeof(RGBQUAD)];
if( m_Palette.GetSafeHandle() != NULL )
m_Palette.Deleteobject();
if( m_nPaletteEntries != 0 ){
LOGPALETTE *pLogPal = (LOGPALETTE *) new char
[sizeof(LOGPALETTE)+
m_nPaletteEntries*sizeof(PALETTEENTRY)];
if( pLogPal != NULL ){
pLogPal->palVersion = 0x300;
pLogPal->palNumEntries = m_nPaletteEntries;
for( int i=0; i pLogPal->palPalEntry[i].peRed =
m_pPalette[i].rgbRed;
pLogPal->palPalEntry[i].peGreen =
m_pPalette[i].rgbGreen;
pLogPal->palPalEntry[i].peBlue =
m_pPalette[i].rgbBlue;
}
m_Palette.CreatePalette( pLogPal );
delete [] pLogPal;
}
}
m_BitCount = 24; //24位位图
p = m_pDibBits; //指向位图数据的指针,用来执行处理操作用
bitmap_size = m_dwDibSize - (m_pDibBits - m_pDib);//真正的位图数据的大小(即除头结构外)
tag = BFH.bfReserved1;
return( TRUE );
}
BOOL CDib::Save( const char *pszFilename ) //保存含有隐藏信息的bmp
{
if( m_pDib == NULL )
return( FALSE );
CFile cf;
if( !cf.Open( pszFilename
CFile::modeCreate | CFile::modeWrite ) )
return( FALSE );
try{
BITMAPFILEHEADER BFH;
memset( &BFH 0 sizeof( BITMAPFILEHEADER ) );
BFH.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8128 2004-06-05 11:49 数字水印\MyImageWork\DIB.cpp
文件 1028 2004-06-05 11:21 数字水印\MyImageWork\DIB.h
文件 2553 2004-06-04 14:26 数字水印\MyImageWork\MainFrm.cpp
文件 1598 1998-01-01 12:26 数字水印\MyImageWork\MainFrm.h
文件 4334 2004-06-05 09:46 数字水印\MyImageWork\MyImageWork.cpp
文件 4843 2004-06-05 11:44 数字水印\MyImageWork\MyImageWork.dsp
文件 547 2003-05-08 16:03 数字水印\MyImageWork\MyImageWork.dsw
文件 1411 2003-05-08 15:42 数字水印\MyImageWork\MyImageWork.h
文件 10325 2004-06-05 11:39 数字水印\MyImageWork\MyImageWork.rc
文件 1842 2003-05-08 15:42 数字水印\MyImageWork\MyImageWorkDoc.cpp
文件 1530 2003-05-08 15:42 数字水印\MyImageWork\MyImageWorkDoc.h
文件 6607 2004-06-05 11:32 数字水印\MyImageWork\MyImageWorkView.cpp
文件 2224 2004-06-05 11:12 数字水印\MyImageWork\MyImageWorkView.h
文件 4431 2003-05-08 15:42 数字水印\MyImageWork\ReadMe.txt
文件 403 2003-05-08 15:42 数字水印\MyImageWork\res\MyImageWork.rc2
文件 1078 2003-05-08 15:42 数字水印\MyImageWork\res\MyImageWorkDoc.ico
文件 1078 2004-06-05 11:38 数字水印\MyImageWork\res\SECUR02A.ICO
..A.SH. 4096 2007-06-15 22:21 数字水印\MyImageWork\res\Thumbs.db
目录 0 2007-06-15 22:21 数字水印\MyImageWork\res
文件 1339 2004-06-05 11:39 数字水印\MyImageWork\resource.h
文件 213 2003-05-08 15:42 数字水印\MyImageWork\StdAfx.cpp
文件 1054 2003-05-08 15:42 数字水印\MyImageWork\StdAfx.h
目录 0 2007-06-15 22:21 数字水印\MyImageWork
目录 0 2007-06-15 22:21 数字水印
----------- --------- ---------- ----- ----
60880 25
评论
共有 条评论