解决VC中图像缩小失真的问题:利用CDC::SetStretchBltMode
2011-08-16 22:27
344 查看
最近在处理图像放大缩小时,发现使用StretchBlt和StretchDIBitsStretchDIBits函数都有很大的失真问题存在。搜索MSDN(http://msdn.microsoft.com/zh-cn/library/s5a0ksxd(v=VS.80)),发现可以利用
CDC::SetStretchBltMode
函数解决。一般COLORONCOLOR模式典型地用于保留彩色位图中的颜色。
StretchBlt[b]函数的位图拉伸模式。其原型如下:[/b]
int SetStretchBltMode( int nStretchMode );
nStrechMode可以选择下表中的值之一(HALFTONE):
使用消除和现在的像素颜色值进行逻辑与(and)操作运算。如果该位图是单色位图,那么该模式以牺牲白色像素为代价,保 留黑色像素点。
[b]使用消除和现在的像素颜色值进行逻辑或(or)操作运算。[/b]
COLORONCOLOR: 删除像素。该模式删除所有消除的像素行,不保留其信息。
HALFTONE: 将源矩形区中的像素映射到目标矩形区的像素块中,覆盖目标像素块的一般颜色与源像素的颜色接近。在设置完
HALFTONE拉伸模之后,应用程序必须调用SetBrushOrgEx函数来设置刷子的起始点。如果没有成功,那么会出现刷子没对准的情况。
如果函数执行成功,那么返回值就是先前的拉伸模式[b]STRETCH_ANDSCANS, STRETCH_DELETESCANS,
STRETCH_ORSCANS中的一种[/b]。如果函数执行失败,那么返回值为0。
BLACKONWHITE(STRETCH_ANDSCANS)和WHITEONBLACK(STRETCH_ORSCANS)模式典型地用来保留单色位图中的前景像素。COLORONCOLOR(STRETCH_DELETESCANS)模式则典型地用于保留彩色位图中的颜色。
HALFTONE模式比其他三种模式需要对源图像进行更多的处理,也比其他模式慢,但它能产生高质量图像,也应注意在设置HALFTONE模式之后,应调用SetBrushOrgEx函数以避免出现刷子没对准现象。
Parameters
nStretchModeSpecifies the stretching mode. It can be any of the following values:
Value | Description |
---|---|
BLACKONWHITE | Performs a Boolean AND operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves black pixels at the expense of white pixels. |
COLORONCOLOR | Deletes the pixels. This mode deletes all eliminated lines of pixels without trying to preserve their information. |
HALFTONE | Maps pixels from the source rectangle into blocks of pixels in the destination rectangle. The average color over the destination block of pixels approximates the color of the source pixels. |
| After setting the HALFTONE stretching mode, an application must call the Win32 function SetBrushOrgEx to set the brush origin. If it fails to do so, brush misalignment occurs. |
STRETCH_ANDSCANS | Windows 95/98: Same as BLACKONWHITE |
STRETCH_DELETESCANS | Windows 95/98: Same as COLORONCOLOR |
STRETCH_HALFTONE | Windows 95/98: Same as HALFTONE. |
STRETCH_ORSCANS | Windows 95/98: Same as WHITEONBLACK |
WHITEONBLACK | Performs a Boolean OR operation using the color values for the eliminated and existing pixels. If the bitmap is a monochrome bitmap, this mode preserves white pixels at the expense of black pixels. |
Return
Value
The previous stretching mode. It can be STRETCH_ANDSCANS, STRETCH_DELETESCANS, or STRETCH_ORSCANS.
Remarks
The bitmap-stretching mode defines how information is removed from bitmaps that are compressed by using the function.
The BLACKONWHITE (STRETCH_ANDSCANS) and WHITEONBLACK (STRETCH_ORSCANS) modes are typically used to preserve foreground pixels in monochrome bitmaps. The COLORONCOLOR (STRETCH_DELETESCANS)
mode is typically used to preserve color in color bitmaps.
The HALFTONE mode requires more processing of the source image than the other three modes; it is slower than the others, but produces higher quality images. Also note that SetBrushOrgEx must be called
after setting the HALFTONE mode to avoid brush misalignment.
Additional stretching modes might also be available depending on the capabilities of the device driver.
相关文章推荐
- SetSTretchBltMode解决图像失真问题
- vc代码显示图像的质量问题,SetStretchBltMode的作用
- 解决位图失真-SetStretchBltMode
- 解决位图失真-SetStretchBltMode()
- 解决位图失真-SetStretchBltMode
- VC++中StretchBlt图像失真问题的解决办法
- SetStretchBltMode() 防止图片失真
- SetStretchBltMode() 防止图片失真
- StretchBlt之前防止图片失真SetStretchBltMode(COLORONCOLOR);
- VC++ MFC 中的SelectPalette()函数和SetStretchBltMode()函数
- VC++中StretchBlt图像失真问题的解决办法
- SetStretchBltMode函数的问题
- VC++中StretchBlt图像失真问题的解决办法
- VC++中StretchBlt图像失真问题的解决办法
- VC 解决图片失真问题
- 使用StretchBlt之前一定要用SetStretchBltMode(COLORONCOLOR)
- 解决Android ImageView用setImageDrawable方法图片缩小的问题
- SetStretchBltMode
- SetStretchBltMode-WINDOWS API
- 关于GDI图像放大缩小StretchBlt显示,图像失真的解决