Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在.NET 2.0 VB应用程序中为x86编译时,BitBlt函数生成空位图_Vb.net_X86_Bitblt - Fatal编程技术网

Vb.net 在.NET 2.0 VB应用程序中为x86编译时,BitBlt函数生成空位图

Vb.net 在.NET 2.0 VB应用程序中为x86编译时,BitBlt函数生成空位图,vb.net,x86,bitblt,Vb.net,X86,Bitblt,我的VB项目中有一个BitBlt包装函数。当编译为任何CPU时,它都可以正常工作,但当我将它瞄准x86时,它会创建一个空位图。我必须使用x86,因为应用程序的其他部分需要它。有什么想法吗?代码如下: Imports System.Drawing.Imaging ''' <summary> ''' Provides the static method ControlCapture used to ''' take screenshots of the specified contro

我的VB项目中有一个BitBlt包装函数。当编译为任何CPU时,它都可以正常工作,但当我将它瞄准x86时,它会创建一个空位图。我必须使用x86,因为应用程序的其他部分需要它。有什么想法吗?代码如下:

Imports System.Drawing.Imaging

''' <summary>
''' Provides the static method ControlCapture used to
''' take screenshots of the specified control.
''' </summary>
''' <remarks>This fails unless compiled targeting Any CPU!!!</remarks>
Public Class ControlCapture

    ''' <summary>
    ''' Pointer to gdi.exe win32 function.
    ''' </summary>
    ''' <param name="hDestDC">destination device context</param>
    ''' <param name="x">x coord. of output rectangle</param>
    ''' <param name="y">y coord. of output rectangle</param>
    ''' <param name="nWidth">width of source and dest. rectangle</param>
    ''' <param name="nHeight">height of source and dest. rectangle</param>
    ''' <param name="hSrcDC">source device context</param>
    ''' <param name="xSrc">x coord. of rectangle to capture</param>
    ''' <param name="ySrc">y coord. of rectangle to capture</param>
    ''' <param name="dwRop">mode (raster op)</param>
    ''' <returns>0 on failure, non-zero on success</returns>
    ''' <remarks>from http://support.microsoft.com/kb/147810 </remarks>
    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 Long

    ''' <summary>
    ''' Grab a screen capture of the given control.
    ''' </summary>
    ''' <param name="control">control to grab</param>
    ''' <returns>Bitmap image</returns>
    ''' <remarks>used by mappoint map viewer and bing map viewer</remarks>
    Public Shared Function ControlCapture(ByVal control As Control) As Bitmap

        'capture params
        Dim width As Integer = control.Width
        Dim height As Integer = control.Height

        'output object
        Dim bitmap As Bitmap = New Bitmap(width, height, PixelFormat.Format32bppArgb)

        'get handles to source and destination objects as graphics
        Dim sourceGraphics As Graphics = control.CreateGraphics()
        Dim destGrahpics As Graphics = Drawing.Graphics.FromImage(bitmap)

        'actual handles
        Dim sourceGraphicsPointer As System.IntPtr = sourceGraphics.GetHdc()
        Dim destGraphicsPointer As System.IntPtr = destGrahpics.GetHdc()

        'get references as ints
        Dim destAddress As Integer = destGraphicsPointer
        Dim sourceAddress As Integer = sourceGraphicsPointer

        'call win32 api
        BitBlt(destAddress, 0, 0, width, height, sourceAddress, 0, 0, Codes.SourceCopy)

        'clean up
        sourceGraphics.ReleaseHdc(sourceGraphicsPointer)
        destGrahpics.ReleaseHdc(destGraphicsPointer)

        Return bitmap
    End Function

    ''' <summary>
    ''' SRCCOPY(CC0020)      Copies the source bitmap to destination bitmap.
    ''' </summary>
    ''' <remarks>From http://support.microsoft.com/kb/147810 </remarks>
    Private Enum Codes
        SourceCopy = &HCC0020
    End Enum

End Class
导入System.Drawing.Imaging
''' 
''提供用于
''拍摄指定控件的屏幕截图。
''' 
''除非针对任何CPU编译,否则将失败!!!
公共类控制捕获
''' 
指向gdi.exe win32函数的“”指针。
''' 
''目标设备上下文
''x坐标。输出矩形的形状
“我是库德。输出矩形的形状
“源和目标的宽度”。矩形
''源和目标的高度。矩形
''源设备上下文
''x坐标。要捕获的矩形的
“我是库德。要捕获的矩形的
''模式(光栅操作)
''失败时为0,成功时为非0
“来自http://support.microsoft.com/kb/147810 
私有声明函数BitBlt Lib“gdi32”(ByVal hDestDC,长度为_
ByVal x长,ByVal y长,ByVal nWidth长_
ByVal N长,ByVal hSrcDC长,ByVal xSrc长_
ByVal ySrc尽可能长,ByVal dwRop尽可能长)尽可能长
''' 
''抓取给定控件的屏幕截图。
''' 
''要抓取的控件
''位图图像
“mappoint地图查看器和bing地图查看器使用”
公共共享函数ControlCapture(ByVal控件作为控件)作为位图
“捕获参数
调宽为整数=控制宽度
将高度调整为整数=控制高度
'输出对象
将位图变暗为位图=新位图(宽度、高度、像素格式.Format32bppArgb)
'将源对象和目标对象的句柄作为图形获取
将sourceGraphics设置为Graphics=control.CreateGraphics()
Dim destGrahpics As Graphics=Drawing.Graphics.FromImage(位图)
“实际处理
Dim SourceGraphicsInter As System.IntPtr=sourceGraphics.GetHdc()
Dim destGraphicsPointer As System.IntPtr=destGrahpics.GetHdc()
'将引用获取为int
Dim destAddress为整数=destGraphicsInter
Dim sourceAddress作为整数=SourceGraphicsInter
'调用win32 api
BitBlt(destAddress,0,0,宽度,高度,sourceAddress,0,0,Codes.SourceCopy)
“清理
sourceGraphics.ReleaseHdc(SourceGraphicsInter)
destGrahpics.ReleaseHdc(destGraphicsPointer)
返回位图
端函数
''' 
''SRCCOPY(CC0020)将源位图复制到目标位图。
''' 
“来自http://support.microsoft.com/kb/147810 
私有枚举码
SourceCopy=&hcc020
结束枚举
末级
谢谢,
brian

这是VB.NET的一个非常经典的问题,pinvoke声明是错误的。您使用的仅适用于VB6,由于历史原因,该语言使用整数表示16位数字,长表示32位数字。这可以追溯到在16位操作系统上运行的早期版本的VB。NET经过重新设计,可以在32位操作系统上正常工作,其整数为32位,长为64位。必须将参数声明为整数。它意外地在64位模式下工作

用于获取正确的声明


请仔细查看Graphics.CopyFromScreen和Control.DrawToBitmap,以获得非常类似的功能,而无需pinvoke。

从现在开始,我的标准操作程序是1)转到堆栈溢出,询问了解他们在做什么的人,2)尝试自己解决它。非常感谢!我也不能使用DrawToBitmap,因为它是一个activex控件,我正试图抓取它。感谢您的建议。Graphics.CopyFromScreen使用BitBlt()。