32位的BMP图象怎么转换成16位的?大家帮帮忙的啊 请求支援 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #include "atlimage.h"/*** 24位位图文件转换为16位位图文件* char* filename: 24位位图文件路径 如果是内存中的数据用IStream** char *destfilename:转换后保存的16位位图文件路径,如果要转换到内存中用IStream**/bool ConvertBmp( char* filename,char *destfilename ){ /** * 使用CImage类装载图像, 并且转换为位图 */ CImage img; HRESULT hr = img.Load( filename ); if( FAILED( hr ) ) { return false; } /** * 确定目标位图的尺寸 */ int width = img.GetWidth(); int height = img.GetHeight(); /** * 创建内存DC */ HDC hdc = ::CreateCompatibleDC( NULL ); /** * 使用DIBSection装载位图 */ BITMAPINFO * info = (BITMAPINFO *)malloc( sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 ); memset(info, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 ); info->bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); info->bmiHeader.biWidth = width; info->bmiHeader.biHeight = height; info->bmiHeader.biPlanes = 1; info->bmiHeader.biBitCount = 16 ; info->bmiHeader.biCompression = BI_RGB; info->bmiHeader.biClrUsed = 0; info->bmiHeader.biClrImportant = 0; void * bits = NULL; HBITMAP hbmp = CreateDIBSection( hdc, info, DIB_RGB_COLORS, &bits, NULL, 0); free(info); if(!hbmp) { DeleteDC( hdc ); return NULL; } SelectObject( hdc, hbmp ); /** * 将CImage类装载的图像内容绘制在hdc上 */ img.Draw( hdc, 0, 0, width, height ); DeleteObject( img.Detach() ); img.Attach( hbmp ); img.Save( destfilename ); DeleteObject( hbmp ); DeleteDC( hdc ); return true;} #include "atlimage.h"??? fatal error C1083: Cannot open include file: 'atlimage.h': No such file or directoryError executing cl.exe.我编译就出现这个错误的。 atlimage.h在E:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include下用.net2003.不要用vc6.0 自己装个.net2003后把此代码拷贝出来就可以用了。 MFC如何在自定义类中添加消息响应 关于多线程传送文件的问题 还是关于winsock.h和winsock2.h的问题,但是新情况 超级菜鸟问题 老问题:设置CListCtrl行高 加上PASCAL关键字可加快程序的运行速度 单行按钮问题,请高手指教! 如何加入一个写好的类? 天一第二菜问题!不是我太懒,而是没时间让我再开动脑筋了! 我看中国的10大品牌软件! 关于VC中使用Office的问题求助 文件访问权限
#include "atlimage.h"/**
* 24位位图文件转换为16位位图文件
* char* filename: 24位位图文件路径 如果是内存中的数据用IStream*
* char *destfilename:转换后保存的16位位图文件路径,如果要转换到内存中用IStream*
*/
bool ConvertBmp( char* filename,char *destfilename )
{
/**
* 使用CImage类装载图像, 并且转换为位图
*/ CImage img;
HRESULT hr = img.Load( filename );
if( FAILED( hr ) )
{
return false;
} /**
* 确定目标位图的尺寸
*/
int width = img.GetWidth();
int height = img.GetHeight();
/**
* 创建内存DC
*/
HDC hdc = ::CreateCompatibleDC( NULL ); /**
* 使用DIBSection装载位图
*/
BITMAPINFO * info = (BITMAPINFO *)malloc( sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 );
memset(info, 0, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256 );
info->bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
info->bmiHeader.biWidth = width;
info->bmiHeader.biHeight = height;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = 16 ;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
void * bits = NULL; HBITMAP hbmp = CreateDIBSection(
hdc,
info,
DIB_RGB_COLORS,
&bits,
NULL,
0); free(info);
if(!hbmp)
{
DeleteDC( hdc );
return NULL;
}
SelectObject( hdc, hbmp ); /**
* 将CImage类装载的图像内容绘制在hdc上
*/
img.Draw(
hdc,
0,
0,
width,
height );
DeleteObject( img.Detach() );
img.Attach( hbmp );
img.Save( destfilename ); DeleteObject( hbmp );
DeleteDC( hdc );
return true;
}
fatal error C1083: Cannot open include file: 'atlimage.h': No such file or directory
Error executing cl.exe.
我编译就出现这个错误的。
用.net2003.不要用vc6.0