说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

如何在内存中画好图,再在屏幕上显示出来?

编辑:说三道四文库 发布时间:2017-01-20 05:32
HTML文档下载 WORD文档下载 PDF文档下载
下面的代码没有达到预期的效果,请高手指点一二,谢谢!
void CSaveBmpView::OnDraw(CDC* pDC)
{
CSaveBmpDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CRect rect;
GetClientRect(&rect);

CDC dcMem;
dcMem.CreateCompatibleDC(pDC);

BITMAPINFO bi;
memset(&bi,0,sizeof(bi));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = rect.Width();
bi.bmiHeader.biHeight = rect.Height();
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;

UINT *bits;
HBITMAP hBitmap = 
::CreateDIBSection(dcMem.m_hDC,&bi,DIB_RGB_COLORS,(void**)&bits,NULL,0);

::SelectObject(dcMem,hBitmap);

//填充一个四边形
int xLeft,yTop,xRight,yBottom;
xLeft = rect.left + 100;
yTop = rect.top + 100;
xRight = rect.right - 100;
yBottom = rect.bottom - 100;

dcMem.MoveTo(xLeft,yTop);
dcMem.LineTo(xRight,yTop+50);
dcMem.LineTo(xRight-50,yBottom);
dcMem.LineTo(xLeft,yBottom-50);
dcMem.LineTo(xLeft,yTop);

CBrush brush;
brush.CreateSolidBrush(RGB(0,255,0));
CBrush* pOldBrush = dcMem.SelectObject(&brush);

dcMem.FloodFill(xLeft+10,yTop+50,RGB(0,0,0));

dcMem.SelectObject(pOldBrush);
//End fill!

pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcMem,rect.left,rect.top,
SRCCOPY);

SaveBmpToFile("Temp.bmp",&bi,bits);
}

int CSaveBmpView::SaveBmpToFile(const char *filename, BITMAPINFO *info, UINT *bits)
{
FILE* fp;
UINT size, //Size of file
infosize, //Size of bitmap info
bitsize;  //Size of bitmap pixels
BITMAPFILEHEADER header;
if((fp = fopen(filename,"wb")) == NULL)
return -1;
if(info->bmiHeader.biSizeImage == 0)
bitsize = (info->bmiHeader.biWidth *
info->bmiHeader.biBitCount+7)/8*
abs(info->bmiHeader.biHeight);
else
bitsize = info->bmiHeader.biSizeImage;

infosize = sizeof(BITMAPINFO);
size = sizeof(BITMAPFILEHEADER)+infosize+bitsize;

header.bfType = 'MB';
header.bfSize = size;
header.bfReserved1 = 0;
header.bfReserved2 = 0;
header.bfOffBits = sizeof(BITMAPFILEHEADER)+infosize;

if(fwrite(&header,1,sizeof(BITMAPFILEHEADER),fp) < 
sizeof(BITMAPFILEHEADER))
{
fclose(fp);
return -1;
}

if(fwrite(info,1,infosize,fp) < infosize)
{
fclose(fp);
return -1;
}

if(fwrite(bits,1,bitsize,fp) < bitsize)
{
fclose(fp);
return -1;
}

fclose(fp);
return 1;
}
不要使用 CreateDIBSection, 还是使用 CBitmap 比较好,使用CreateDIBSection 一般是为了直接操作位图数据。
http://www.ccw.com.cn/htm/produ/special/VC/jiqiao/01_9_13_20.asp
::CreateDIBSection(dcMem.m_hDC,&bi,DIB_RGB_COLORS,(void**)&bits,NULL,0);
上面的DC用pDC,不要用dcMem
楼上几位还是没发现问题啊,我调试了半天才发现
void CSaveBmpView::OnDraw(CDC* pDC)
{
CSaveBmpDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CRect rect;
GetClientRect(&rect);

CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
dcMem.FillSolidRect(rect, RGB(255,255,255));

BITMAPINFO bi;
memset(&bi,0,sizeof(bi));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = rect.Width();
bi.bmiHeader.biHeight = rect.Height();
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
UINT *bits;
HBITMAP hBitmap = 
::CreateDIBSection(dcMem.m_hDC,&bi,DIB_RGB_COLORS,(void**)&bits,NULL,0);

::SelectObject(dcMem.GetSafeHdc(), hBitmap);
dcMem.FillSolidRect(rect, RGB(255,255,255));

//&Igrave;&icirc;&sup3;&auml;&Ograve;&raquo;&cedil;&ouml;&Euml;&Auml;±&szlig;&ETH;&Icirc;
int xLeft,yTop,xRight,yBottom;
xLeft = rect.left + 100;
yTop = rect.top + 100;
xRight = rect.right - 100;
yBottom = rect.bottom - 100;

dcMem.MoveTo(xLeft,yTop);
dcMem.LineTo(xRight,yTop+50);
dcMem.LineTo(xRight-50,yBottom);
dcMem.LineTo(xLeft,yBottom-50);
dcMem.LineTo(xLeft,yTop);

CBrush brush;
brush.CreateSolidBrush(RGB(0,255,0));
CBrush* pOldBrush = dcMem.SelectObject(&brush);

dcMem.FloodFill(xLeft+10,yTop+50,RGB(0,0,0));

dcMem.SelectObject(pOldBrush);
//End fill!

pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcMem,rect.left,rect.top,
SRCCOPY);

SaveBmpToFile("Temp.bmp",&bi,bits);
}
有两种方法
1.记录点然后把他连起来。
2.记录图象的特征然后绘画出来,如圆有圆心,半径。画N个圆就存储N个这样的信息然后绘画出来。
deadhorse(死马) 是正确的!

我试了!
up
CBitmap backBitmap;
CDC mem;
mem.CreateCompatibleDC(pDC);
backBitmap.CreateCompatibleBitmap(&mem,wid,hei);
CBitmap* oldBit=mem.SelectObject(&backBitmap);
mem.TextOut("It's testing !",102,11);
pDC->BitBlt(0,0,wid,hei,&mem,0,0,SRCCOPY);
mem.SelectObject(oldBit);
Summly创始人:12岁开始编程 17岁公司卖了3000万美元 因SaaS与NoSQL,Oracle雄风不在? 那些年云计算领域的大牛们 回顾:那些被平台方封杀的第三方应用 [热帖推荐] 中国的程序员,真的“短命”吗? 聚焦HTML5移动开发 第六届英特尔杯大学生软件开发大赛开幕 虚拟化技术新星Pluribus Networks获中国VC青睐 可穿戴开发!Pebble Watchface SDK 4月发布 我想做个程序员:一位编程小白的App开发故事 Go 1.1发布,支持向后兼容 Polycode:免费、开源的跨平台(游戏和APP)开发工具 为何大多数云计算公司注定要失败 究竟是什么让Redshift比Hive快10倍?! [评论]将Linux拒之门外 微软被开源社区指控垄断 精细化运营:友盟统计分析SDK 3.0版本发布 “锤子OS”功能猜测与罗式对比营销 神奇!1KB JavaScript代码编写的3D蜜蜂 顶尖技术人员“兜售”的顶尖编程语言、扩展工具等 移动阅读商业化:Flipboard支持用户DIY杂志 全球移动App:Top 52发行商排行榜 知新网CTO:从程序员的视角,实践精益创业 罗永浩锤子ROM:小团队的75项微创新 谷歌知识图谱扩展到Android平板电影中 云计算大战升温 服务器OEM押注OpenStack 如何将战略性的内容策略融入进网页设计中 数字天堂CTO:移动行业应用开发“潜规则” 众联智领CTO:从idea到面目全非的创业产品 CMDN Club 25期:knewone与路况电台的精益创业法则 Windows Blue的孪生兄弟?Office Gemini浮出水面 HTML5开发平台Ludei将支持3D游戏开发 《二战风云》发布至今,已为顽石互动狂赚2.7亿 激情放送 五位QQ号,100块,你会要吗? 555~~~~挂了PASCAL挂了,5555~~~~我学不好DELPHI 了5555谁帮我呀!!! 有编过游戏修改器的高手吗? jinesc领分~~~ 如何使UpDown每次增加或减少0.5? 有个问题很困惑,请教 上傳后,服務器端如何接收? 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!! 我快神经了,求救 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!!!! 别笑我傻,又有简单问题 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!!! 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!!!!!!!! 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!!!!! 大家都谈谈建立什么样的目录结构能更好的管理硬盘里的东东 lilo 如何设置??请赐教!! 各位高手好!现在有谁是正在使用 LINUX 上网的.报一下好吗!!!!!!!!!!!1 mts是什么? mts是什么?? 学习汇编要什么基础,要看什么样的书,有没有好的汇编的电子参考书下载呢? 腾讯的qq怎么不好用了? 有CCNA,Scjp2,高程的计算机本科生能卖多少?(答者有分,只能给33分,没办法) word的表格问题 如果开另外一个线程来进行注册码检验,是否比较难CRACK? 请问高程考试考试的难度 怎么让程序启动的时候接受参数? mts是什么??? 我也调查:这里有多少冠名以“独孤”的,为何独孤???? 菜鸟SOS 个人论:编写程序方法论(原作者,huangbeyond) 向流版主学习,戒网!戒网!成天在网上瞎转,不如下去加强学习,碰到问题再上网寻求答案,天天在网上泡得久了,看到各大PB网站的编程技巧都有些视而不见了.....到PB论坛很多人都象到自己喜爱的聊天室了,到论坛好象就是来聊天一样.....戒网!戒网! 如何编写一个集成Ms Word的控件,能够处理WEB上的文件排版 怎么不能下载呢? 我是女孩,有人信吗??嘻嘻~~ 谁知道关于用vc编游戏的书,请各位大虫们介绍介绍好吗?谢谢了!!!!!!!!!! 有关sql server不能显示中文啊?? 关于B/S动态刷新问题 想不到,摩机三年今天居然栽了 beginpaint函数有什么用? 在PowerBuilder中怎么才能得到当前程序运行的路径? Sybase PowerDesigner v7.5 的中文学习材料谁有? 哪位大虾能够作一个查看游戏图片的辅助工具 请问casl汇编和asm有什么不同??谢谢!!!!!!!!!!111 Activex Document下载问题 kingxing(在江湖上混口饭吃) 能不能让程序一直运行哪一段呢?? linux 能上csdn吗?来报个名 我想找一位root。 TERMINATE是这么用吗??? 在江湖上混口饭吃不行啊! 你哪样的,虽然可以到最底层,但是不能一直在最底层哟! 有什么办法能一直在最底层吗/? 打印一行字,如何控制字间距? 英语翻译National laws shall always take precedence over International guidelines.Cases made to International courts are likely to give precedence to a combination of the OECD Recommendation and either the European Data Privacy Directive or APEC P 英语翻译换了新版之后貌似点朗读没反映啊 英语翻译我的名字叫 关启成 怎么翻译成英文名字啊(不是翻译成汉语拼音的那种)?例如:林志颖 jimmy lin 林心如 ruby 任家萱 seina 等等 英语翻译请帮忙翻译这段话:The $47.3 fee is a DHL charge for Quarantine processing carried out by Department of Agriculture,Fisheries and Forestry(DAFF).When shipments are inspected ,DAFF charges DHL for the quarantine inspection services 英语翻译他十三岁了,但他仍旧太依靠他父母.琳达外出时,你能照看她的儿子吗?我们起床早是为了赶早班车.不要花太多时间在电脑游戏上.我认为小孩子没必要学英语.你介意打开窗户吗?要学 英语翻译我的名字叫 林智健 不是拼音的哪种啊 英语翻译If boy wizard(巫师) Harry Potter uses his magic to capture(迷住) the hearts of millions of teenagers,high school students Gabriella and Troy have charmed American boys and girls with their stories of campus life.They are the leading c 英语翻译,求助!谢绝谷歌翻译在这个世界上,职业经理人永远比老板的数量多,职业经理人要想实现自己的职业理想,只能依靠老板搭建的舞台,虽然老板离不开职业经理人这个群体,但作为个体, 英语翻译我的名字是赖明珠,谁能翻译?女生的. 英语翻译The discovery,development,and clinical use of antibiotics during the 20th century have decreased substantially the morbidity and mortality from bacterial infections.The antibiotic era started with the therapeutic application of sulfonamid 英语翻译This contact proved invaluable in 2012,when,back in Syria to cover a Free Syrian Army–controlled area in Aleppo,Tomada traveled with the elite group,this time on a mission to attack an armored battalion of the Syrian regime.En route to 英语翻译我有个金山词霸,但是感觉发音太差,有没有发音准点的 英语翻译The DCS 968 series Auto start Controller is designed for use in applications involving control and safety monitoring of stationary engines.The use of the controller increases reliability and simplifies wring of the control panel. 英语翻译让想法轻松上路...就是上面这一句,希望有文采一点,好记一点. 请问有没有可以发音的英汉翻译工具 英语翻译The following is an e-mail sent to you by an administrator of "Channel [v]Thailand".If this message is spam,contains abusive or other comments youfind offensive please contact the webmaster of the board at the followingaddress:webmaster@c 英语翻译~不要谷歌百度什么的Let us take a serious, reasonable look at what the results might be if such a proposal were accepted. Families might use the time for a real family hour. Without the distraction of TV, they might sit around tog 用英语翻译:这儿很漂亮,我非常喜欢这 英语翻译I helped out a women several years ago that made mens underwear.She would send me samples to try on an I would send pic or video back to her so she could see the fitting.Would not have a problem offering you that help if you are intereste 英语翻译翻译的时候最好带点意译.熟悉各种Windows系统、Office、Excel和互联网的基本操作,并且通过全国计算机信息高新技术办公软件应用模块(Windows平台Office系列)操作员考试.有基本的药理知 我也认为它很漂亮,英文翻译这个它是个物品,比如我看到一双很漂亮的鞋子,别人说很不错的鞋子,我说,我也认为它很漂亮或者是很好看,很喜欢都可以,谢谢高手点拨 英语翻译The old lady pulled her spectacles down and looked over them about the room .Then she put them up and looked out under them.She seldom or never looked through them for so samll a thing as a boy.They were her fancy pair,the pride of her he 英语翻译我的家乡在泰山脚下,泰山是一座千古名山,动植物种类丰富,有着庞大的生态系统和许多有趣的生物链.比如,绿色植物草,苔藓等被小虫子吃,小虫子被麻雀吃,而麻雀又被蛇吃,最终蛇被 英语翻译:我觉得这里很漂亮,你们觉得呢? 英语翻译Make a periscopeHave you ever been in a crowd at a football match and wished you were much taller?Don't worry about it now.A Home-made periscope could be the answer to your wish.This is what you do...1.Look at the diagram and draw the sha 英语翻译"To think that I'm not going to use cell phone when at the same time I can still use my laptop,I still can read a paper I can stilll change my pants while driving at 65 mph.I think there is just something wrong," an offcial said.Other cri “你觉得我帅吗?” 英语翻译一下. 英语翻译Since detention of a ship is a serious matter involving many issues,it may be in the best interest of the PSCO to act with other interested parties. 英语翻译自由视野下《飘》男主人公的人生遭际内容提要:瑞德是南方名门望族中的不肖子,早期沉浸在社会自由的瑞德随心所欲地做着离经叛道的事情,继而媚兰的善良让他受欲望奴役的心 发现自己的美,求英语翻译 英语翻译lazy.I wasn't surprised to find that my worst report was from my science teacher.it's just that i find science really difficult.that‘s about all the news i have for now.send their love. 英语翻译In this case,therecommender system accumulates user ratings of items,identifies users with common ratings,and offersrecommendations based on inter-user comparison.As such,the CF recommender compares researchers’ ratings ofresources,and 英语翻译:这个俱乐部是个时髦的场所 英语翻译AVL techniques have widely been perceived as useful technologies in many APTS areas,such as automatic vehicle location,vehicle component monitoring,automatic passenger counters,electronic fare boxes,timed transfers,traffic signal preempti 英语翻译Tony 'Doc' Shiels是翻译成 托尼“医生”希尔斯 还是 托尼-多可-希尔斯 英语翻译简洁点即可、 英语翻译用机器翻译的话麻烦也稍微修改一下,意思大概正确,语句通顺即可The two factors (dependent variables) considered for this research study were the systems integration complexity (systems integration process complexity 英语翻译就是只要翻译出 的英文相似的音、 英语翻译:“我经常访问你的博客!” 英语翻译用机器翻译的话麻烦也稍微修改一下,意思大概正确,语句通顺即可 Fig.7 illustrates improvements at five different levels in the systems integration process complexity on the vertical axis as a result of the requireme 英语翻译 中文翻译英文,比较准确的,还有读音的,章 英语翻译Out of the night that covers me,Black as the pit from pole to pole,I thank whatever gods may beFor my unconquerable soul.In the fell clutch of circumstanceI have not winced nor cried aloud.Under the bludgeonings of chanceMy head is bloody 音标翻译英语,麻烦了[i:kəu] 要取英文名的,谢谢了 英语翻译要美语发音!要会念名字.有的不是单词只是名字缩写之类的它也能念!软件和在线都可以.但一定要符合上2个要求.不是的就别回答了好么~要能翻译的。全是英文的咱不会用~你那个我 英语翻译Dear Mark,New York is finally getting a real sales manager.Congratulations on your new promotion.Your marketing ability has put you well above everyone else in the company,and probably everyone else in the industry.The company will benefi 淑女英文名我想要E或C开头的要淑女又甜美的不要复制 最好是自己想的要有英文和中文唷有追分 告别时刻英文歌词的读音 用中文翻译一下,要整段歌词的 英语翻译HappinessHappiness means different things to different people.For example,some students believe that if they have much money or a large number of possessions,they will be happy.They believe that they will be able to do anything they want 淑女型英文名可以是一些有意思的东西名字~不过一定要有意义 不要太长了 let it go 英文歌词翻译中文读音的歌词.谢谢!The snow glows white on the mountain tonight;Not a footprint to be seen;A kingdom of isolation;And it looks like I'm the queen;The wind is howling like this swirling storm inside;Couldn't keep 英语翻译B:hey ,what if you did not have adventures ,I think my life is estimated to be the case.After graduating from college ,took barely a month to feed their own money,what are generally married woman,birth wanderers .Nothing exciting live to 名叫林佳丽,起什么英文名字好? 英语翻译Alex Reid Best Of Me oh oh oh ohoh best of me ohwake up all alone nownever felt so freegot caught up and it drive mywhen i thought of youwere good for mei thought what i live forunder your controlyou've left so emptybut i never felt so ha 谷歌英语在线翻译发音准不准? 佳丽求漂亮英文名. 高手翻译下英文歌词 ~~~I watch the city burnThese dreams like ashes float awayYour voice I never heardOnly silenceWhere were you when our hearts were bleedingWhere were you when it all crashed downNever thought that you'd deceive meWhere are 英语翻译货物已经发出,航空小包是无跟踪查询信息的.前一段时间由于欧美出现雪灾.导致一些邮件延误.现在情况已经好转,相信你很快就会收到货,请您耐心等待.我已经到邮局做书面查询,结 Google在线翻译的那个英文发音算标准吗?http://translate.google.com/#就是按那个小喇叭,它会读给你听的.我感觉它英文读得蛮有味道的唉~~~没有给人一种明显是干巴巴的机器发出来的感觉.所以请问 英语翻译本人叫王宝森,男,各位帮忙翻译成英文名字,带发音,
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn