怎么处理bmp的放大缩小绘制!

yosoft 2008-06-12 05:29:22
需求:
GDI绘制一个矩形,在矩形框内装载一个bmp对象;
矩形放大缩小时,bmp也随之放大缩小。

test代码:
//RECT rc :矩形大小;传入的rc为放大缩小后的矩形。
出现问题:bmp范围小于rc时;会绘制多个bmp填满rc区域;怎么根据矩形大小绘制呢?请大侠指点!


void CBmptl::DrawBoundtl(CDC* pDC,RECT rc){

CBrush brush;
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP_TLQC);
brush.CreatePatternBrush(&bitmap);

CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brush);

pDC->FillRect(&rc, &brush);
pDC->SelectObject(pOldBrush);
brush.DeleteObject();
}
...全文
168 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
yosoft 2008-06-20
  • 打赏
  • 举报
回复
最近又在忙别的事情,最后也没有bmp了,直接自己绘图了,效果不错,但好麻烦。
yosoft 2008-06-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lsldd 的回复:]
为什么要用位图画刷?
用StretchBlt难道不好吗?
[/Quote]

实现功能就是在矩形区域内绘制bmp图形;
我当时只是采用画刷而已,不要影响大家思路。
我试试
pDC->StretchBlt();
palmax 2008-06-13
  • 打赏
  • 举报
回复
[Quote=引用楼主 yosoft 的帖子:]
需求:
GDI绘制一个矩形,在矩形框内装载一个bmp对象;
矩形放大缩小时,bmp也随之放大缩小。

test代码:
//RECT rc :矩形大小;传入的rc为放大缩小后的矩形。
出现问题:bmp范围小于rc时;会绘制多个bmp填满rc区域;怎么根据矩形大小绘制呢?请大侠指点!


void CBmptl::DrawBoundtl(CDC* pDC,RECT rc)
{
CBrush brush;
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP_TLQC);
brush.CreatePatternBrush(&bitmap);

CBrush* pOldBrush = (CBrush*)pDC->SelectObject(&brush);

pDC->FillRect(&rc, &brush);
pDC->SelectObject(pOldBrush);
brush.DeleteObject();
}
[/Quote]

你为什么要用brush去画呢?
brush.CreatePatternBrush(&bitmap); 只是把位图选入刷子了,但是位图本身没有放大或缩小
正确的做法是:
CBitmap* oldBmp = pDC->SelectObject(&bitmap);
pDC->StretchBlt(....); // 参数自己查MSDN
pDC->SelectObject(oldBmp);
startstartsvip 2008-06-12
  • 打赏
  • 举报
回复
呵呵,感到是很有趣的话题。

帮顶一个。

自己画的话的好像是在转矩阵。
leo201592 2008-06-12
  • 打赏
  • 举报
回复

BOOL StretchBlt(
int x,
int y,
int nWidth,
int nHeight,
CDC* pSrcDC,
int xSrc,
int ySrc,
int nSrcWidth,
int nSrcHeight,
DWORD dwRop
);就能达到效果
baihacker 2008-06-12
  • 打赏
  • 举报
回复
如果一定要自己绘制,这样
如果四个像素是
0 10
10 20
两个方向各放大1.5倍后
0 5 10
5 10 15
10 15 20

如果是用函数:
CDC::StretchBlt
Copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.


BOOL StretchBlt(
int x,
int y,
int nWidth,
int nHeight,
CDC* pSrcDC,
int xSrc,
int ySrc,
int nSrcWidth,
int nSrcHeight,
DWORD dwRop
);


Parameters
x
Specifies the x-coordinate (in logical units) of the upper-left corner of the destination rectangle.

y
Specifies the y-coordinate (in logical units) of the upper-left corner of the destination rectangle.

nWidth
Specifies the width (in logical units) of the destination rectangle.

nHeight
Specifies the height (in logical units) of the destination rectangle.

pSrcDC
Specifies the source device context.

xSrc
Specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle.

ySrc
Specifies the x-coordinate (in logical units) of the upper-left corner of the source rectangle.

nSrcWidth
Specifies the width (in logical units) of the source rectangle.

nSrcHeight
Specifies the height (in logical units) of the source rectangle.

dwRop
Specifies the raster operation to be performed. Raster operation codes define how GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. This parameter may be one of the following values:

BLACKNESS Turns all output black.

DSTINVERT Inverts the destination bitmap.

MERGECOPY Combines the pattern and the source bitmap using the Boolean AND operator.

MERGEPAINT Combines the inverted source bitmap with the destination bitmap using the Boolean OR operator.

NOTSRCCOPY Copies the inverted source bitmap to the destination.

NOTSRCERASE Inverts the result of combining the destination and source bitmaps using the Boolean OR operator.

PATCOPY Copies the pattern to the destination bitmap.

PATINVERT Combines the destination bitmap with the pattern using the Boolean XOR operator.

PATPAINT Combines the inverted source bitmap with the pattern using the Boolean OR operator. Combines the result of this operation with the destination bitmap using the Boolean OR operator.

SRCAND Combines pixels of the destination and source bitmaps using the Boolean AND operator.

SRCCOPY Copies the source bitmap to the destination bitmap.

SRCERASE Inverts the destination bitmap and combines the result with the source bitmap using the Boolean AND operator.

SRCINVERT Combines pixels of the destination and source bitmaps using the Boolean XOR operator.

SRCPAINT Combines pixels of the destination and source bitmaps using the Boolean OR operator.

WHITENESS Turns all output white.

Return Value
Nonzero if the bitmap is drawn; otherwise 0.
lsldd 2008-06-12
  • 打赏
  • 举报
回复
为什么要用位图画刷?
用StretchBlt难道不好吗?
coverallwangp 2008-06-12
  • 打赏
  • 举报
回复
我上次也遇到了这个问题,到最后没有办法就自己绘制,不用bitmap了。
不知道谁有解决方案,期待高手的回答。
coverallwangp 2008-06-12
  • 打赏
  • 举报
回复
up

64,651

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧