毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc

上传人:laozhun 文档编号:2390077 上传时间:2023-02-17 格式:DOC 页数:7 大小:133KB
返回 下载 相关 举报
毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc_第1页
第1页 / 共7页
毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc_第2页
第2页 / 共7页
毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc_第3页
第3页 / 共7页
毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc_第4页
第4页 / 共7页
毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc》由会员分享,可在线阅读,更多相关《毕业论文(设计)基于VB 与VC 编程技术的位图图像处理系统的开发.doc(7页珍藏版)》请在三一办公上搜索。

1、基于VB与VC编程技术的位图图像处理系统的开发 黄立靖 (福建林业职业技术学院 福建南平 353000)摘要 结合VB与VC编程技术的优点,可开发出快速、高效的位图图像处理系统。介绍了在VB中通过调用API函数快速获取位图图像像素信息和显示位图图像的方法,说明了VC中编写DLL及在VB中调用的过程。关键词 VB,VC,DLL, API函数Development Of Bitmap Graphics Processing System Based ON Programming Technology Of VB and VCHUANG Li-jing(Fu Jian Forestry Vocati

2、onal & Technical College FuJian NanPing 353000)Abstract IT can develop Bitmap Graphics processing system rapidly and efficiently that combines the advantage of programming technology with VB and VC. The paper introduces the method of obtaining information of Bitmaps pixels and displaying Bitmap Grap

3、hics, through calling of Windows API function in VB, explains the process of DLL programming in VC and calling in VB.Key words VB, VC, DLL, API function 1、 引言位图图像又称点阵图像,是由许多不同颜色的点组成的,这些点被称为像素。在计算机处理位图时,需要进行大量的数值计算,像素越高,分辩率越高,计算量就越大,图像处理的速度就越慢。以在图像处理中常用的模板处理为例,对于一幅模板为N*N的图像,就要进行9(N-2)2次乘法,8(N-2)2次加法操

4、作,算法复杂度为O(N2),运算量非常之大。鉴于此,笔者认为可利用VB与VC编程技术上各自的优点来开发出一种快速、高效的位图图像处理系统。VB在界面编程中具有所见即所得的优势,且编程快速、简单,但代码运行较慢。VC编写的程序,编译后代码的执行速度比VB快,但编程较为复杂。因此,位图图像处理系统的开发,对于系统界面等不涉及大量数值计算的程序可利用VB的优势来编程,对于位图图像处理等涉及大量数值计算的程序可利用VC的优势来编程。可采用在VB中调用VC编写的DLL(动态链接库)的方法,就能实现VB与VC的优化组合,这样开发出的位图图像处理系统不仅能提高编程的效率,同时也能保证处理位图图像速度。以下介

5、绍开发过程:2、 VB中调用DLL的实现DLL(Windows API是一种典型的DLL库)是一种包含了一些函数和例程的可执行文件,其本身并不能单独运行,但可为其它应用程序提供服务。在VB中调用DLL时,必须首先告诉VB如何正确地向DLL例程传递函数,可使用Declare语句对DLL中的例程进行声明,Declare语句的语结构有如下两种:Public/Private Declare Sub name Lib “libname” Alias “aliasname” (arghlist)Public/Private Declare Function name Lib “libname” Alias

6、 “aliasname” (arghlist) as type如果一个DLL过程没有返回值,就应该被声明为子过程的形式,即采用前一种语法结构;如果一个DLL过程返回了一个可用于表达式的值,则应被声明为函数的形式,即采用后一种语法结构。在类模块或窗体模块中的DLL过程只能被声明为Private,并只能在模块中使用。在标准模块中,只能声明为Public,且这个DLL过程能为工程中所有的模块访问。其中name指明了过程名,其命名需遵循VB命名规则。Lib子句指明了包含所声明过程的动态链接库或代码资源,该动态链接库或代码资源由libname指定,如果后缀名为“.dll”,则可以省略。如果libname

7、没有指定路径名,VB会按如下规则进行搜索:.exe文件所在目录。当前目录。Windows系统目录。Windows目录。Path环境变量中的目录。VB在传递参数时有两种方式,按值的方式(Byval)和按引用的方式(ByRef)传递。按值的方式传递时,传递的实际上是变量的一个副本,接受该参数的过程所作的改变只针对该副本,不会影响变量本身。按引用的方式传递是VB6的默认方式。在这种方式中,实际上传递的并不是变量的值,而是指向这个变量的32位地址。所调用的过程根据这个地址来获取变量的实际值。这样过程可以通过对地址中的值的修改来达到永久修改参数原有值的目的。C/C+的数据类型与VB的数据类型并不相同。在

8、VB中调用C 或C+编写的DLL,需要知道两者数据类型之间的对应关系,如表1所示。当然,并不是两者之间所有的数据类型都能找到对应关系。声明了过程后,就可以使用该过程名name访问该过程。表1 C中数据类型与声明DLL过程所用参数格式的对应关系C中的数据类型VB里Declare中使用的参数声明格式C中的数据类型VB里Declare中使用的参数声明格式BOOLByVal variable as longBYTEByVal variable as byteCHARByVal variable as byteDWORDByVal variable as longHWND,HDC等Windows句柄By

9、Val variable as longINT,UNITByVal variable as longLONGByVal variable as longLPDWORDByVal variable as longLPINT,LPUNITByVal variable as longLPVOIDByVal variable as anyNULLAs any 或ByVal variable as longSHORTByVal variable as IntegerWORDByVal variable as IntegerLPWORDByVal variable as Integer3、 VB中获取位图

10、的像素信息和显示位图的实现为了在VB中快速地获取像素信息和显示位图,需要使用三个API函数。可以利用API函数GetObject获取位图格式信息;用GetBitmapBits获取位图的像素信息;用SetBitmapBits将像素信息返回给位图并显示出来。31 GetObject函数在VB中的声明如下:Public/Private Declare Function GetObject Lib “gdi32” Alias “GetObjectA” (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As LonghObjec

11、t是图像对象(位图、画笔、刷子、字体、调色板等)的句柄,nCount是接受对应图像对象信息的结构的字节数,lpObject是指向接受对应图像信息的结构的指针。如果是位图,hObject是位图的句柄,而接受图像信息的结构为BITMAP,其定义如下:Public/Private Type BITMAP 14 bytesbmType As LongbmWidth As LongbmHeight As LongbmWidthBytes As LongbmPlanes As IntegerbmBitsPixel As IntegerbmBits As LongEnd Type其中BmType指明了位图的

12、类型,这个值必须是0;bmWidth代表位图以像素为单位的图像宽度;bmHeight代表位图以像素为单位的图像高度;bmWidthBytes指明了每个扫描行的字节数(即以字节为单位的图像宽度),这个值必须可被2整除;bmPlanes代表图像的颜色面数;bmBitsPixel指明每个像素用几位数据来表示(8,16,24,32);bmBits是指向图像数据的指针。32 GetBitmapBits和SetBitmpBits分别用于从位图中获取图像中的像素信息和把像素信息返回给位图。两者在VB中的声明如下:Public/Private Declare Function GetBitmapBits Li

13、b “gdi32”Alias “GetBitmapBits” (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As LongPublic/Private Declare Function SetBitmapBits Lib “gdi32”Alias “SetBitmapBits” (ByVal hBitmap As Long, ByVal dwCount As Long, lpBits As Any) As Long其中hbitmap是位图的句柄,dwCount是图像信息的大小,lpBits是保存图像信息的地址。33

14、三个API函数的用法。首先新建一个VB工程,在其中添加一个Picture Box控件Picture1,在其中加载一幅图片。然后分别声明以上三个API函数和BITMAP类型。最后添加下面的代码。Dim Besult As Long, totbytes As LongDim bmp As BITMAPDim lmgArray() As ByteResult=GetObject(Picture1.Picture.handle, Len(bmp), bmp) 获取位图图像格式信息totbytes=bmp.bmWidthBytes*bmp.bmHeight 总共要多多少个Byte来存图ReDim lmg

15、Array(totbytes)Result=GetBitmapBits(Picture1.Picture.handle, totbytes,lmgArray(0) 获得图片像素信息在这里加入对图像像素数据进行处理的程序Call SetBitmapBits(Picture1.Picture.handle, totbytes,lmgArray(0) 显示处理结果Picture1.Refresh4、 VC中编写DLL,供VB中调用为了在VC编写的动态链接库中处理图像像素,需要VB把获取的位图图像像素信息传送给DLL。上文,已经介绍了获取像素信息的方法,这里说明的是把存有像素信息的数组传送给DLL。由

16、于数值型的数组在VB中其数据是连续存放的,而在C/C+中数组可以等价于指向数组第1个元素的指针。那么可以用引用的方式把VB中数组的第1个元素的地址传给VC编写的DLL,在DLL中用一个指针来接收,这样就达到了传递数组的目的。至于从DLL传递数组给VB,方法相同,只不过过程相反而已。注意在这个过程中VB和VC中的数据类型一定要对应的。同时,因为在C/C+中并不检查数组的界限,需要告诉DLL数组的大小。下面以对灰度图像进行锐化为例说明编写和调用DLL的一般方法。先在VC中选择新建一个MFC AppWizard(dll)项目,取名为Mydll,并接受下面的选项的默认设置。接着在Globals项下添加

17、一个新过程Myfunc,其定义如下:void_stdcall Myfunc(LPVOID PicArray, long PicHeight, long PicWidth) /PicArray是接受数组的指针,PicHeight和PicWidth分别是图像以字节为单位的高度和宽度。 long Presult; int temple33; /定义模板数组 for (int i=0;i3;i+) /模板数组赋值 for (int j =0;j3;j+) templeij =-1; temple11=9; for (i=1;ipicHeight 2;i+) for (int j=1; jpicWidt

18、h-2;j+) PResult=0; /对像素进行模板操作 for (int k=0; k3; k+) for(int l=0; l255) PResult=255; if (PResult0) PResult=0;*(picArray +(i 1)*picWidth +j) = (byte) PResult;在建立项目之前,需要在Mydll.def文件的EXPORTS项下加一行Myfunc。因为在VB的命名规则中第1个字符不允许为“-”,而VC编写的过程,其默认的导出函数,会在函数名前加“-”。所以只有强制VC按要求命名导出函数。生成Mydll.dll后,将Mydll.dll复制到VB编写的

19、执行文件所在的目录。在VB中对应声明Myfunc过程。Private Declare Sub Myfunc Lib “mydll” (PicArray as Byte, PicHeight as Long, PicWidth as Long)最后就可以直接在模块中调用Myfunc,处理位图图像像素数据了。5、 结束语将VB与VC相结合,利用VB界面设计简单并可调用DLL和VC能处理大量复杂运算的优点,不但能缩短编程时间,提高工作效率,而且还能开发出快速、高效的位图图像处理系统,对编写图像处理程序而言,能起到事半功倍的效果,确实是一种可行的好方法。参考文献 1、 谭浩强. Visual Basi

20、c 程序设计. 北京:高等教育出版社,1999.11. P221P250.2、 郑阿奇. Visual C+ 6.0 教程. 北京:机械工业出版社,2004.9. P255P281作者简介黄立靖,男,1965年10出生,汉族,籍贯:福州,高级讲师,大学本科学历,工学士学位。在福建林业职业技术学院信息工程系从事计算机科学与技术的教学工作,主要研究方向为计算机图形图像的制作与处理。联系电话:13859488170,联系地址:南平金山路福建林业职业技术学院信息工程系;邮编:353000。Editors note: Judson Jones is a meteorologist, journalist

21、 and photographer. He has freelanced with CNN for four years, covering severe weather from tornadoes to typhoons. Follow him on Twitter: jnjonesjr (CNN) - I will always wonder what it was like to huddle around a shortwave radio and through the crackling static from space hear the faint beeps of the

22、worlds first satellite - Sputnik. I also missed watching Neil Armstrong step foot on the moon and the first space shuttle take off for the stars. Those events were way before my time.As a kid, I was fascinated with what goes on in the sky, and when NASA pulled the plug on the shuttle program I was h

23、eartbroken. Yet the privatized space race has renewed my childhood dreams to reach for the stars.As a meteorologist, Ive still seen many important weather and space events, but right now, if you were sitting next to me, youd hear my foot tapping rapidly under my desk. Im anxious for the next one: a

24、space capsule hanging from a crane in the New Mexico desert.Its like the set for a George Lucas movie floating to the edge of space.You and I will have the chance to watch a man take a leap into an unimaginable free fall from the edge of space - live.The (lack of) air up there Watch man jump from 96

25、,000 feet Tuesday, I sat at work glued to the live stream of the Red Bull Stratos Mission. I watched the balloons positioned at different altitudes in the sky to test the winds, knowing that if they would just line up in a vertical straight line we would be go for launch.I feel this mission was crea

26、ted for me because I am also a journalist and a photographer, but above all I live for taking a leap of faith - the feeling of pushing the envelope into uncharted territory.The guy who is going to do this, Felix Baumgartner, must have that same feeling, at a level I will never reach. However, it did

27、 not stop me from feeling his pain when a gust of swirling wind kicked up and twisted the partially filled balloon that would take him to the upper end of our atmosphere. As soon as the 40-acre balloon, with skin no thicker than a dry cleaning bag, scraped the ground I knew it was over.How claustrop

28、hobia almost grounded supersonic skydiverWith each twist, you could see the wrinkles of disappointment on the face of the current record holder and capcom (capsule communications), Col. Joe Kittinger. He hung his head low in mission control as he told Baumgartner the disappointing news: Mission abor

29、ted.The supersonic descent could happen as early as Sunday.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move th

30、rough the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere.

31、 As he crosses the boundary layer (called the tropopause), he can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet (22.7 miles/36.53 kilometers). Here, Fearless Felix will unclip. He will roll back the door.Then, I would assume, he will slowly step out on

32、to something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving

33、into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to

34、stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In o

35、rder to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and

36、me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).It might not be the moon, but Kittinger free fell from 102,800 feet in 1960 - at the dawn of an infamous space race that captured the hearts of many. Baumgartner will attempt to break that record, a feat that boggles the mind. This is one of those monumental moments I will always remember, because there is no way Id miss this.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号