IImage绘制特定区域
Imaging是WINCE 5.0之后才加入的COM组件,其中包含了如下的接口
Interface |
Description |
Performs basic operations on bitmap images. |
|
Allows applications to access pixel data of a bitmap image object. |
|
The basic interface to an image object. |
|
A low-level interface to an image decoder object. |
|
Used for encoding images. |
|
Allows an image source, such as an image decoder, and an image sink to exchange data. |
|
Used to create bitmaps and images and to manage image encoders and decoders. |
Imageing使用起来非常的方便。其中我们最常用的是IImage这个接口来进行画图工作。
HRESULT Draw(
HDC hdc,
const RECT* dstRect,
OPTIONAL const RECT* srcRect
);
Draw的这个接口非常简单,但是会很容易去误解微软的意思。显示整副图片只要将srcRect参数赋值NULL即可.但如果是显示特定的区域呢?比如说,有一副800*600的图片,我只想显示一半,估计很多人,不会仔细看文档,而会是凭借经验直接这么写。
RECT rcSrc = {0,0,400,600};
m_pImage->Draw(hdc,&rcWnd,&rcSrc);
这样画出来可能能看到很大的像素,要么什么到看不到,为何?且看微软文档。
srcRect
[in] An optional pointer to a RECT that specifies, in 0.01mm units, the portion of the image to be drawn in dstRect.To display the entire image, set this value to NULL.
他是以0.01毫米为单位的,我们以像素为单位,画出来当然是差千里了。仔细看微软Iimage提供的方法。
Grouping |
Method |
Display |
|
Information |
GetPhysicalDimension这个接口刚好是得到图片物理尺寸的方法。那么我们只要把像素转换为物理尺寸就行了。调用下GetImageInfo和GetPhysicalDimension,分别获得物理尺寸和像素,用物理尺寸除以像素,就是他们的比例。
详见 Image_draw
void Image_draw(IImage *pImage, HDC hdc, RECT &dstRect, RECT &srcRect)
{
ImageInfo imgInfo;
SIZE size;
pImage->GetPhysicalDimension(&size);
pImage->GetImageInfo(&imgInfo);
RECT srcPhysicalRect={srcRect.left * size.cx/imgInfo.Width,
srcRect.top * size.cy/imgInfo.Height,
srcRect.right * size.cx/imgInfo.Width,
srcRect.bottom * size.cy/imgInfo.Height};
pImage->Draw(hdc, &dstRect, &srcPhysicalRect);
}
本片主要是将IImag绘制特定区域,其他就不讲了。