这几天一直让一个问题困扰,但是在论坛上求助,大家只是告诉个方法。本人太笨,大侠们授人以渔,但是我希望得到的是鱼。这几天问了这么多,思路是会了,但是要我实现还是能力不够阿,大家看我的等级就知道了,我做这个能力还不行。不要说我是吃干饭的,真的是没这个本事,哪位有时间帮帮一看。
要求是: 画一副图,这幅图的样点是可以随意的增加和缩小。意思和孙鑫第十课讲的差不多,只不过孙鑫里面是把一个图片随着窗口缩放而缩小和放大。而我的要求是,在一个固定的区域,缩放一副图,这幅图,可能比这个区域要大,也可能要小。但是画出来,就只能在指定区域,如果比指定区域小,那么就放大,如果小,就缩小到指定区域。
这是我这几天发的帖子
http://topic.csdn.net/u/20090525/23/933df510-4d3a-424d-af70-71de7f91dc83.html
http://topic.csdn.net/u/20090524/22/408fb997-e602-4c10-b961-ae959fd09569.html
http://topic.csdn.net/u/20090526/17/e89bbea0-d808-4b4b-9eb6-35b8ded471d0.html?seed=1178298753
代码如下(别人帮忙改的,但好像还是不行)
CPaintDC dc(this);
CRect rect;
int width=2000,height=200,drawWidth=1500,drawHeight=100;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bm;
bm.CreateCompatibleBitmap(&dc,width,height); //这里的宽与高必须包含for循环中的x,y坐标上的最小值与最大值
dcMem.SelectObject(bm);
dcMem.Rectangle(&rect);
for (int a=0;a <drawWidth;a++)
{
for (int b=0;b <drawHeight;b++)
{
dcMem.SetPixel(a+width-drawWidth,b+height-drawHeight,RGB(a+100,255,255));
// dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,width-drawWidth,height-drawHeight,drawWidth,drawHeight,SRCCOPY );//将含有绘图像素的那块区域缩放到对话框上
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
}
}
// dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,width-drawWidth,height-drawHeight,drawWidth,drawHeight,SRCCOPY );//将含有绘图像素的那块区域缩放到对话框上
DeleteObject(bm);
DeleteObject(dcMem); 我自己的
CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bm;
bm.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
dc.SelectObject(bm);
dc.Rectangle(&rect);
for (int a=0;a <1500;a++)
{
for (int b=0;b <100;b++)
{
dc.SetPixel(a+500,b+100,RGB(a+100,255,255));
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
}
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),dc,0,0,rect.Width(),rect.Height(),SRCCOPY );
}
DeleteObject(bm);
DeleteObject(dc);
要求是: 画一副图,这幅图的样点是可以随意的增加和缩小。意思和孙鑫第十课讲的差不多,只不过孙鑫里面是把一个图片随着窗口缩放而缩小和放大。而我的要求是,在一个固定的区域,缩放一副图,这幅图,可能比这个区域要大,也可能要小。但是画出来,就只能在指定区域,如果比指定区域小,那么就放大,如果小,就缩小到指定区域。
这是我这几天发的帖子
http://topic.csdn.net/u/20090525/23/933df510-4d3a-424d-af70-71de7f91dc83.html
http://topic.csdn.net/u/20090524/22/408fb997-e602-4c10-b961-ae959fd09569.html
http://topic.csdn.net/u/20090526/17/e89bbea0-d808-4b4b-9eb6-35b8ded471d0.html?seed=1178298753
代码如下(别人帮忙改的,但好像还是不行)
CPaintDC dc(this);
CRect rect;
int width=2000,height=200,drawWidth=1500,drawHeight=100;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bm;
bm.CreateCompatibleBitmap(&dc,width,height); //这里的宽与高必须包含for循环中的x,y坐标上的最小值与最大值
dcMem.SelectObject(bm);
dcMem.Rectangle(&rect);
for (int a=0;a <drawWidth;a++)
{
for (int b=0;b <drawHeight;b++)
{
dcMem.SetPixel(a+width-drawWidth,b+height-drawHeight,RGB(a+100,255,255));
// dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,width-drawWidth,height-drawHeight,drawWidth,drawHeight,SRCCOPY );//将含有绘图像素的那块区域缩放到对话框上
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
}
}
// dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,width-drawWidth,height-drawHeight,drawWidth,drawHeight,SRCCOPY );//将含有绘图像素的那块区域缩放到对话框上
DeleteObject(bm);
DeleteObject(dcMem); 我自己的
CRect rect;
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bm;
bm.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());
dc.SelectObject(bm);
dc.Rectangle(&rect);
for (int a=0;a <1500;a++)
{
for (int b=0;b <100;b++)
{
dc.SetPixel(a+500,b+100,RGB(a+100,255,255));
//pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
}
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),dc,0,0,rect.Width(),rect.Height(),SRCCOPY );
}
DeleteObject(bm);
DeleteObject(dc);
你把位图创建大一点就可以了,不用CreateCompatiableBitmap,直接创建,参数照MSDN上来。别的地方都不用改
就ok了:)
看你都发了三次贴了,不容易啊
GetClientRect(&rect);
CDC dc;
dc.CreateCompatibleDC(pDC);
CBitmap bm;
bm.CreateBitmap(1024,1024,NULL, 3, NULL);
dc.SelectObject(bm);
dc.Rectangle(CRect(20,20,500,500));
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,1024,1024,SRCCOPY ); DeleteObject(bm);
DeleteObject(dc);
亲自做的,可以实现,你贴过去就可以看见了,我默认创建的是1024*1024的画布,最后pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,1024,1024,SRCCOPY );的参数要看清楚了,&dc后面的是内存上画布大小,最后显示中间有拉伸的正方形。
:)
lz的反应让我想起了原来学vc在群里骂没人教的日子,呵呵,入门确实有点难,加油!