如何将Form保存为Tiff图像文件? [英] How to save a Form as a Tiff image file?

查看:77
本文介绍了如何将Form保存为Tiff图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设计了一个表单并在表单上设置了一个标签。

现在我想将表单保存为任何位置的Tiff图像。



 私有 共享 函数 BitBlt(_ 
ByVal hdcDest 作为 IntPtr ,_
ByVal nXDest As < span class =code-keyword>整数,_
ByVal nYDest As 整数,_
ByVal nWidth As 整数,_
ByVal nHeight 正如 整数,_
ByVal hdcSrc 作为 IntPtr ,_
ByVal nXSrc 作为 整数,_
ByVal nYSrc 作为 整数,_
< span class =code-keyword> ByVal dwRop As 整数 _
作为 布尔
结束 功能


私有 共享 SRCCOPY 作为 整数 =& HCC0020
私有 Sub Button1_Click( ByVal 发​​件人作为系统。对象 ByVal e As System.EventArgs)句柄 Button1.Click
< span class =code-keyword> Dim path As String = C:\ Users \ KavtikP \Desktop\KpDesk\Test.Tiff
SaveFormToFile (,路径)

结束 Sub

私有 Sub SaveFormToFile( ByVal sourceForm 作为表单, ByVal filename As String
Dim formGraphics As Graphics = sourceForm.CreateGraphics()

Dim bufferRect = sourceForm.ClientRectangle

Dim buffer < span class =code-keyword> As Image = 位图(bufferRect.Width,bufferRect.Height,formGraphics)
Dim bufferGraphics As Graphics = Graphics.FromImage(buffer)

Dim formDC As IntPtr = formGraphics.GetHdc()
Dim bufferDC As IntPtr = bufferGraphics.GetHdc ()

BitBlt(bufferDC, 0 0 ,bufferRect.Width,bufferRect.Height,formDC, 0 0 ,SRCCOPY)

bufferGraphics。 ReleaseHdc(bufferDC)
formGraphics.ReleaseHdc(formDC)

bufferGraphics.Dispose()
formGraphics.Dispose()

' 'buffer.Save(filename,System.Drawing.Imaging.ImageFormat.Jpeg)

buffer。保存(filename,System.Drawing.Imaging.ImageFormat.Tiff)

buffer.Dispose()
结束 Sub

私有 Sub Button2_Click ( ByVal sender As System。 Object ByVal e As System.EventArgs)句柄 Button2.Click

Dim screenRect As Rectangle = Screen.PrimaryScreen.WorkingArea
Dim myBitmapScreenShot = 位图(screenRect.Width,screenRect.Height)
使用 targetGraphics As Graphics = Graphics.FromImage(myBitmapScreenShot)
targetGraphics.CopyFromScreen( 0 ,< span class =code-digit> 0 , 0 0 大小(myBitmapScreenShot.Width,myBitmapScreenShot.Height))
结束 使用
结束 Sub

解决方案

请参阅..

http://social.msdn.microsoft.com/Forums/windows/en-US/b7e7232d-8056-4671-b6d9-e3a3918f27ce / capture-windows-form-images-to-tiff [ ^ ]

http://forums.devshed.com/net-development-87/ convert-windows-form-gui-into-image-ie-jpg-tiff-618672.html [ ^ ]

http://go4answers.webhost4life.com/Example/save-form-image-file-156950.aspx [ ^ ]

在第3个链接中,使用.tiff代替。 JPG

I have design a form and set a label on form.
now i want to save a form a as a Tiff image any of a location.

Private Shared Function BitBlt( _
ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, _
ByVal nYDest As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As Integer _
) As Boolean
End Function
 

Private Shared SRCCOPY As Integer = &HCC0020
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim path As String = "C:\Users\KavtikP\Desktop\KpDesk\Test.Tiff"
SaveFormToFile(Me, path)
 
End Sub
 
Private Sub SaveFormToFile(ByVal sourceForm As Form, ByVal filename As String)
Dim formGraphics As Graphics = sourceForm.CreateGraphics()
 
Dim bufferRect = sourceForm.ClientRectangle
 
Dim buffer As Image = New Bitmap(bufferRect.Width, bufferRect.Height, formGraphics)
Dim bufferGraphics As Graphics = Graphics.FromImage(buffer)
 
Dim formDC As IntPtr = formGraphics.GetHdc()
Dim bufferDC As IntPtr = bufferGraphics.GetHdc()
 
BitBlt(bufferDC, 0, 0, bufferRect.Width, bufferRect.Height, formDC, 0, 0, SRCCOPY)
 
bufferGraphics.ReleaseHdc(bufferDC)
formGraphics.ReleaseHdc(formDC)
 
bufferGraphics.Dispose()
formGraphics.Dispose()
 
''buffer.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)
 
buffer.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff)
 
buffer.Dispose()
End Sub
 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
 
Dim screenRect As Rectangle = Screen.PrimaryScreen.WorkingArea
Dim myBitmapScreenShot = New Bitmap(screenRect.Width, screenRect.Height)
Using targetGraphics As Graphics = Graphics.FromImage(myBitmapScreenShot)
targetGraphics.CopyFromScreen(0, 0, 0, 0, New Size(myBitmapScreenShot.Width, myBitmapScreenShot.Height))
End Using
End Sub

解决方案

See..
http://social.msdn.microsoft.com/Forums/windows/en-US/b7e7232d-8056-4671-b6d9-e3a3918f27ce/capturing-windows-form-images-to-tiff[^]
http://forums.devshed.com/net-development-87/convert-windows-form-gui-into-image-i-e-jpg-tiff-618672.html[^]
http://go4answers.webhost4life.com/Example/save-form-image-file-156950.aspx[^]
In 3rd link,use .tiff instead of .jpg


这篇关于如何将Form保存为Tiff图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆