在程序中,我设计新建一个窗口,窗口上按要求划线与点,然后把画的内容存为一张图片。请问:如果能把窗口内容存为一个图片文件?

解决方案 »

  1.   

    可以加入系统热键,按下后响应键盘SHIFT+PrScrn键,将当前窗体保存在内存中。
    然后把图像从内存中保存为一个图片文件就OK了
      

  2.   

    Private Sub Command1_Click()
        Me.AutoRedraw = True
        Me.Line (0, 0)-(1000, 1000)
        Me.AutoRedraw = False
        SavePicture Me.Image, "E:\aa.bmp"
    End Sub
      

  3.   

    谢谢楼上各位朋友!按蚜虫老师教师的代码可以,但问题是,我的窗体都是用各种控件,象 line shape 等组合成的,而用这个代码存成的图片中却没有。烦请再指点,谢谢。
      

  4.   

    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 LongPrivate Const SRCCOPY = &HCC0020 ' (DWORD) dest = sourcePrivate Sub Command1_Click()
        Dim nWidth As Long, nHeight As Long
        Picture1.Width = Me.ScaleWidth
        Picture1.Height = Me.ScaleHeight
        nWidth = Me.ScaleWidth / Screen.TwipsPerPixelX
        nHeight = Me.ScaleHeight / Screen.TwipsPerPixelY
        Picture1.AutoRedraw = True
        BitBlt Picture1.hDC, 0, 0, nWidth, nHeight, Me.hDC, 0, 0, SRCCOPY
        Picture1.AutoRedraw = False
        SavePicture Picture1.Image, "e:\bb.bmp"
    End Sub设置visible属性把Picture1隐藏。
      

  5.   

    非常感谢蚜虫老师。经测试,这段代码中可以存图片了,现在还有一个问题请教,烦请指点:  根据现在代码,要存图片时,该图片窗口必须放在前台来激活,否则就不能存图。 我现在是一次需要做几百个图片,如果运行程序就其他事都干不成了,如何才能不在前台 show,而只load到内存中的窗口存成图片?
      

  6.   

    我在主窗口frmmain 中放了一个 picture1 ,在模块中写了这个通用过程,运行中提示: f.hDC 是夫效属性值错误,请问是什么原因?怎么解决?谢谢!
    Sub 保存图片(f As Form, savefile As String)
    Dim nWidth As Long, nHeight As LongfrmMain.Picture1.Width = f.ScaleWidth
    frmMain.Picture1.Height = f.ScaleHeight
    nWidth = f.ScaleWidth / Screen.TwipsPerPixelX
    nHeight = f.ScaleHeight / Screen.TwipsPerPixelY
    frmMain.Picture1.AutoRedraw = True
    BitBlt frmMain.Picture1.hDC, 0, 0, nWidth, nHeight, f.hDC, 0, 0, SRCCOPY
    frmMain.Picture1.AutoRedraw = False
    SavePicture frmMain.Picture1.Image, savefile 
    DoEvents
    Set frmMain.Picture1.Picture = Nothing
    End Sub
      

  7.   

    你是怎么调用的 sub 保存图片()的?
    如果哪个窗口名为 form1,则:call 保存图片(form1,"....")
      

  8.   

    我是这样的,程序运行中form1.show 1在form1中,图表画好后,执行  call 保存图片(form1,app.path & "图片.bmp")