我从你的问题中了解到,在退出Button_3下的代码后,你必须通过单击Button_2保存捕获的ScreenShot cliking Button_1而不显示对话框。如果是这样的话--
沿着这条路。。。。。。。。。
一开始
从代码中释放
Dim screenshot As System.Drawing.Bitmap
从Button_1 Sub,并将其粘贴为文档的泛型。
其次
只需复制以下Sub。
Public Sub SaveImage(filename As String, image As Image, Encoder As ImageCodecInfo, EncParam As EncoderParameter)
Dim path As String = System.IO.Path.Combine(My.Application.Info.DirectoryPath, filename & ".jpg")
Dim mySource As New Bitmap(image.Width, image.Height)
Dim grfx As Graphics = Graphics.FromImage(mySource)
grfx.DrawImageUnscaled(image, Point.Empty)
grfx.Dispose()
mySource.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg)
mySource.Dispose()
End Sub
第三
将代码完全保留在Button_2下并剪切&将Button_3下的代码粘贴到Button_2下
立即像这样更改代码。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Private Sub VaryQualityLevel()
' Get a bitmap.
Dim bmp1 As New Bitmap(screenshot)
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)
Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
Dim myEncoderParameters As New EncoderParameters(1)
Dim myEncoderParameter As New EncoderParameter(myEncoder, 50&)
myEncoderParameters.Param(0) = myEncoderParameter
'your Code....// bmp1.Save("c:\TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters)
'// Call the above Sub
SaveImage("C:\Users\User\Desktop\TestPhotoQualityFifty.jpg", bmp1, jgpEncoder, myEncoderParameter)
myEncoderParameter = New EncoderParameter(myEncoder, 100&)
myEncoderParameters.Param(0) = myEncoderParameter
'your Code....// bmp1.Save("c:\TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters)
'// Call the above Sub
SaveImage("C:\Users\User\Desktop\TestPhotoQualityFifty.jpg", bmp1, jgpEncoder, myEncoderParameter)
' Save the bitmap as a JPG file with zero quality level compression.
myEncoderParameter = New EncoderParameter(myEncoder, 0&)
myEncoderParameters.Param(0) = myEncoderParameter
'your Code....// bmp1.Save("c:\TestPhotoQualityFifty.jpg", jgpEncoder, myEncoderParameters)
'// Call the above Sub
SaveImage("C:\Users\User\Desktop\TestPhotoQualityFifty.jpg", bmp1, jgpEncoder, myEncoderParameter)
End Sub 'VaryQualityLevel
剩下的代码仍然存在。
现在完成!
这是示例图像。