当前位置:编程学习 > C#/ASP.NET >>

为什么我生成的图像全是黑的?

--------------------编程问答-------------------- 楼主获取图像的内容是什么? --------------------编程问答-------------------- --------------------编程问答--------------------
Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020

Public Function CaptureScreen() As Image
Dim result As Image
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
Dim sw, sh As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
hBMP = CreateCompatibleBitmap(hDC, sw, sh)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, sw, sh, hDC, 0, 0, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
result = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
Return result
End Function
--------------------编程问答-------------------- 调用范例:
Me.BackgroundImage = CaptureScreen() --------------------编程问答-------------------- 谢谢你的回复,很遗憾,生成的图片全是黑色的。
我这个应用是在一个web application里面,用户按一个键就可以把他的屏幕截下来然后发送给Admin。
我是这么调用的,不知是不是调用有问题:
        Dim pic As Image = CaptureScreen()
        pic.Save("C:\CSDN.jpg", ImageFormat.Jpeg) --------------------编程问答-------------------- 不懂web,我写的winform下的。你测试应该有效果的。web的没试过。 --------------------编程问答-------------------- dim bmp as bitmap=new bitmap() --------------------编程问答-------------------- sw = Screen.PrimaryScreen.Bounds.Width
sh = Screen.PrimaryScreen.Bounds.Height
dim bmp as bitmap=new bitmap(sw,sh) 
dim g as graphics=bmp.creategraphics
g.copyfromscreen(new point(0,0),new point(0,0),new size(sw,sh)) --------------------编程问答-------------------- dim g as graphics=bmp.creategraphics
写错了,
dim g as graphics=graphics.fromimage(bmp) --------------------编程问答--------------------
补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,