| 发表于:2007-02-11 19:16:523楼 得分:20 |
保存用picture的line,circle……方法绘制的图片 见 http://zhidao.baidu.com/question/20086889.html 百度网友 "鲸无敌 "的代码,径调试无误: 按command1按钮保存picture1区域的图片 option explicit private const bi_rgb = 0& private const dib_rgb_colors = 0 ' color table in rgbs private const bitmaptype = &h4d42 private const invalid_handle_value = (-1) private const generic_write = &h40000000 private const create_always = 2 private const file_attribute_normal = &h80 private type bitmapinfoheader '40 bytes bisize as long biwidth as long biheight as long biplanes as integer bibitcount as integer bicompression as long bisizeimage as long bixpelspermeter as long biypelspermeter as long biclrused as long biclrimportant as long end type private type rgbquad rgbblue as byte rgbgreen as byte rgbred as byte rgbreserved as byte end type private type bitmapinfo bmiheader as bitmapinfoheader bmicolors as rgbquad end type private type bitmapfileheader bftype as integer bfsize as long bfreserved1 as integer bfreserved2 as integer bfoffbits as long end type private declare function createcompatibledc lib "gdi32 " (byval hdc as long) as long private declare function createdibsection lib "gdi32 " (byval hdc as long, pbitmapinfo as bitmapinfo, byval un as long, lplpvoid as long, byval handle as long, byval dw as long) as long private declare function deletedc lib "gdi32 " (byval hdc as long) as long private declare function deleteobject lib "gdi32 " (byval hobject as long) as long private declare function selectobject lib "gdi32 " (byval hdc as long, byval hobject as long) as long private declare function bitblt lib "gdi32 " (byval hdestdc as long, byval x as long, byval y as long, byval nwidth as long, byval nheight as long, byval hsrcdc as long, byval xsrc as long, byval ysrc as long, byval dwrop as long) as long private declare function createfile lib "kernel32 " alias "createfilea " (byval lpfilename as string, byval dwdesiredaccess as long, byval dwsharemode as long, byval lpsecurityattributes as long, byval dwcreationdisposition as long, byval dwflagsandattributes as long, byval htemplatefile as long) as long private declare function writefile lib "kernel32 " (byval hfile as long, lpbuffer as any, byval nnumberofbytestowrite as long, lpnumberofbyteswritten as long, byval lpoverlapped as long) as long private declare function closehandle lib "kernel32 " (byval hobject as long) as long private sub command1_click() dim hmemdc as long dim hmembmp as long dim lpmembits as long dim bmp_info as bitmapinfo dim hfile as long dim bmpfile_info as bitmapfileheader dim lpbyteswritten as long picture1.scalemode = vbpixels with bmp_info.bmiheader .bisize = lenb(bmp_info.bmiheader) .biwidth = picture1.scalewidth .biheight = picture1.scaleheight .biplanes = 1 .bibitcount = 24 .bicompression = bi_rgb .bisizeimage = .biheight * (((.biwidth * .bibitcount + 31) and &hffffffe0) \ 8) end with hmemdc = createcompatibledc(picture1.hdc) hmembmp = createdibsection(picture1.hdc, bmp_info, dib_rgb_colors, lpmembits, 0, 0) selectobject hmemdc, hmembmp bitblt hmemdc, 0, 0, bmp_info.bmiheader.biwidth, bmp_info.bmiheader.biheight, picture1.hdc, 0, 0, vbsrccopy hfile = createfile(app.path & "\test.bmp ", generic_write, 0, 0, create_always, file_attribute_normal, 0) if hfile <> invalid_handle_value then with bmpfile_info .bftype = bitmaptype .bfoffbits = 14 + bmp_info.bmiheader.bisize .bfsize = .bfoffbits + bmp_info.bmiheader.bisizeimage end with writefile hfile, bmpfile_info.bftype, 2, lpbyteswritten, 0 writefile hfile, bmpfile_info.bfsize, 12, lpbyteswritten, 0 writefile hfile, bmp_info.bmiheader, bmp_info.bmiheader.bisize, lpbyteswritten, 0 writefile hfile, byval lpmembits, bmp_info.bmiheader.bisizeimage, lpbyteswritten, 0 closehandle hfile end if deleteobject hmembmp deletedc hmemdc end sub | | |
|