这个句子之后,graphics图象容器里面已经有了 截图, 只是怎么把导出 到 (为) 2.jpg就不懂了。或者如何直接储存 图像容器的图片到某一个盘符?
Dim bitmap = New Bitmap(200, 200)
'Dim imageFile As Image = Image.FromFile("d:\2.jpg") 'd:\2.jpg必须存在。创建一个图片。
Dim graphics = Me.CreateGraphics()
graphics.CopyFromScreen(0, 0, 200, 200, New Size(200, 200))
'graphics.DrawImage(imageFile, New Point(0, 0))
'graphics 就已经储存到了picturebox1.image中去了。???
'graphics.Save()
'graphics.DrawImage(bitmap, New Point(0, 0))
'bitmap.Save("d:\2.jpg") '存储一张位图。
6 个解决方案
#1
Dim graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(...)
bitmap.Save(...)
graphics.CopyFromScreen(...)
bitmap.Save(...)
#2
大神,bitmap.save 保存下来的是漆黑一片。
#3
我保存的怎么不黑。
注意,DirectX区域无法截图,比如视频窗口之类的。
注意,DirectX区域无法截图,比如视频窗口之类的。
#4
graphics.CopyFromScreen(0, 0,
0, 0, New Size(200, 200))
好好查下这个函数参数的含义
好好查下这个函数参数的含义
#5
用我这个看看,窗体两个按钮和一个图片框。
Public Class Form1
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByRef lpInitData As Integer) As Integer
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Function GetSerPic(Optional ByVal BitWidth As Integer = -1, Optional ByVal BitHeight As Integer = -1) As Image
If BitWidth < 0 Then BitWidth = My.Computer.Screen.Bounds.Width
If BitHeight < 0 Then BitHeight = My.Computer.Screen.Bounds.Height
Dim Bhandle, DestDC, SourceDC As IntPtr
SourceDC = CreateDC("DISPLAY", Nothing, Nothing, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, BitWidth, BitHeight)
SelectObject(DestDC, Bhandle)
BitBlt(DestDC, 0, 0, BitWidth, BitHeight, SourceDC, 0, 0, &HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
'Dim p2 As New Point(500, 500, 500, 500)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'PictureBox1.Image.Save(Application.StartupPath & "\" & Format(Now, "yyyy年MM月dd日HH点mm分ss秒") & ".jpg")
PictureBox1.Image.Save(Application.StartupPath & "\" & 2 & ".jpg")
End Sub
End Class
Public Class Form1
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByRef lpInitData As Integer) As Integer
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Function GetSerPic(Optional ByVal BitWidth As Integer = -1, Optional ByVal BitHeight As Integer = -1) As Image
If BitWidth < 0 Then BitWidth = My.Computer.Screen.Bounds.Width
If BitHeight < 0 Then BitHeight = My.Computer.Screen.Bounds.Height
Dim Bhandle, DestDC, SourceDC As IntPtr
SourceDC = CreateDC("DISPLAY", Nothing, Nothing, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, BitWidth, BitHeight)
SelectObject(DestDC, Bhandle)
BitBlt(DestDC, 0, 0, BitWidth, BitHeight, SourceDC, 0, 0, &HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
'Dim p2 As New Point(500, 500, 500, 500)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'PictureBox1.Image.Save(Application.StartupPath & "\" & Format(Now, "yyyy年MM月dd日HH点mm分ss秒") & ".jpg")
PictureBox1.Image.Save(Application.StartupPath & "\" & 2 & ".jpg")
End Sub
End Class
#6
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(100, 100)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PictureBox1.Image.Save(Application.StartupPath & "\1.jpg")
End Sub
End Class
帮您把不要的代码去除了一下。谢谢。很有用,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(100, 100)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PictureBox1.Image.Save(Application.StartupPath & "\1.jpg")
End Sub
End Class
帮您把不要的代码去除了一下。谢谢。很有用,
#1
Dim graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(...)
bitmap.Save(...)
graphics.CopyFromScreen(...)
bitmap.Save(...)
#2
大神,bitmap.save 保存下来的是漆黑一片。
#3
我保存的怎么不黑。
注意,DirectX区域无法截图,比如视频窗口之类的。
注意,DirectX区域无法截图,比如视频窗口之类的。
#4
graphics.CopyFromScreen(0, 0,
0, 0, New Size(200, 200))
好好查下这个函数参数的含义
好好查下这个函数参数的含义
#5
用我这个看看,窗体两个按钮和一个图片框。
Public Class Form1
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByRef lpInitData As Integer) As Integer
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Function GetSerPic(Optional ByVal BitWidth As Integer = -1, Optional ByVal BitHeight As Integer = -1) As Image
If BitWidth < 0 Then BitWidth = My.Computer.Screen.Bounds.Width
If BitHeight < 0 Then BitHeight = My.Computer.Screen.Bounds.Height
Dim Bhandle, DestDC, SourceDC As IntPtr
SourceDC = CreateDC("DISPLAY", Nothing, Nothing, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, BitWidth, BitHeight)
SelectObject(DestDC, Bhandle)
BitBlt(DestDC, 0, 0, BitWidth, BitHeight, SourceDC, 0, 0, &HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
'Dim p2 As New Point(500, 500, 500, 500)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'PictureBox1.Image.Save(Application.StartupPath & "\" & Format(Now, "yyyy年MM月dd日HH点mm分ss秒") & ".jpg")
PictureBox1.Image.Save(Application.StartupPath & "\" & 2 & ".jpg")
End Sub
End Class
Public Class Form1
Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByRef lpInitData As Integer) As Integer
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
Function GetSerPic(Optional ByVal BitWidth As Integer = -1, Optional ByVal BitHeight As Integer = -1) As Image
If BitWidth < 0 Then BitWidth = My.Computer.Screen.Bounds.Width
If BitHeight < 0 Then BitHeight = My.Computer.Screen.Bounds.Height
Dim Bhandle, DestDC, SourceDC As IntPtr
SourceDC = CreateDC("DISPLAY", Nothing, Nothing, 0)
DestDC = CreateCompatibleDC(SourceDC)
Bhandle = CreateCompatibleBitmap(SourceDC, BitWidth, BitHeight)
SelectObject(DestDC, Bhandle)
BitBlt(DestDC, 0, 0, BitWidth, BitHeight, SourceDC, 0, 0, &HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
'Dim p2 As New Point(500, 500, 500, 500)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'PictureBox1.Image.Save(Application.StartupPath & "\" & Format(Now, "yyyy年MM月dd日HH点mm分ss秒") & ".jpg")
PictureBox1.Image.Save(Application.StartupPath & "\" & 2 & ".jpg")
End Sub
End Class
#6
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(100, 100)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PictureBox1.Image.Save(Application.StartupPath & "\1.jpg")
End Sub
End Class
帮您把不要的代码去除了一下。谢谢。很有用,
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p1 As New Point(0, 0)
Dim p2 As New Point(100, 100)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
PictureBox1.Image = pic
End Using
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PictureBox1.Image.Save(Application.StartupPath & "\1.jpg")
End Sub
End Class
帮您把不要的代码去除了一下。谢谢。很有用,