有时我们可能需要将内存中HBITMAP位图句柄指向的位图,保存成其他类型的图片文件。这里面牵涉到图片类型之间的转换,其实实现也很简单,我们直接使用GDI+中的Bitmap类就可以实现,相关步骤为:
1)将位图句柄指向的位图资源添加到Bitmap对象中;
2)根据传入的保存的文件完整路径中的图片文件后缀去判断要保存成哪种类型的图片;
3)调用Bitmap::Save接口即可保存成对应类型的图片。
实现代码如下:
// 获取jpeg等编码Clsid
BOOL GetEncoderClsid( const WCHAR* format, CLSID* pClsid )
{
UINT num = 0; // number of image encoders
UINT size = 0; // size of the image encoder array in bytes
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize( &num, &size );
if( 0 == size )
{
return FALSE; // Failure
}
pImageCodecInfo = (ImageCodecInfo*)( malloc( size ) );
订阅专栏 解锁全文
988

被折叠的 条评论
为什么被折叠?



