如何截取图片

木梓油 2005-07-12 01:59:34
我在做一个换皮肤的控件,现在的问题是:如何从一张图片里根据坐标和大小截取一张小图片,然后把它保存起来
请教!
...全文
1018 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
dirdirdir3 2005-08-04
CDC的bitblt
回复
zhongjishiming 2005-08-04
就是从一个源矩形设备移动一个位图到一个目标矩形,若需要适合目标矩形的尺寸,则拉升或
压缩该位图
回复
zhongjishiming 2005-08-04
用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:





回复
木梓油 2005-07-13
在C#中调用该BitBlt ,里面的HDC在托管代码中如何表示啊?
回复
kugou123 2005-07-12
同意用BitBlt复制到内存
回复
漂流的代码 2005-07-12
用BitBlt就行了
BitBlt(小图的dc句柄,0,0,宽,高,包含原图的句柄,xBegin,yBegin,SRCCOPY);
例子:
有一个图片保存在hbmp1(HBITMAP),保存
HBITMAP hbmp2;
HDC hdc;
HDC hdcmem;
hdc = GetDC(hWnd);
hdcmem=CreateCompatibleDC(hdc);
HBITMAP hbmpOld=(HBITMAP)SelectObject(hdc,hbmp1);
hbmp2=CreateCompatibleBitmap(hdc,50,50);
HBITMAP hbmpOld2=(HBITMP)SelectObject(hdcmem,hbmp2);
BitBlt(hdcmem,0,0,50,50,hdc,20,25,SRCCOPY);
SelectObject(hdc,hbmpOld);
SelectObject(hdcmem,hbmpOld2);
DeleteDC(hdcmem);
//保存hbmp2
DeleteObject(hbmp2);
ReleaseDC(hWnd,hdc);
回复
发帖
界面
创建于2007-09-28

1.5w+

社区成员

VC/MFC 界面
申请成为版主
帖子事件
创建了帖子
2005-07-12 01:59
社区公告
暂无公告