屏幕图像如何快速保存到数组当中?

helson2008 2009-02-21 05:48:29
我要用VB实现以下功能:
从屏幕的(x,y)坐标开始得到100*100像素大小内的屏幕的图像数据,本人用有form的的picturebox已经实现,但是我想把这个功能做成dll,不想带有form窗口,请问如何解决呢,再网上也看了一下,可能用到Createdibsection、CreateDIBSection和bitble函数,现在想请教大家这个dll如何用VB写呢,请给出具体的代码(VB的),能够解决我这个问题的给100分。
...全文
246 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lianghong 2009-04-13
  • 打赏
  • 举报
回复
sendkeys"{PRTSC}"
再从剪贴板中提取你要的的图像,简单吧?
熊孩子开学喽 2009-03-26
  • 打赏
  • 举报
回复
楼主怎么大号小号一起上阿.

-

只要有句柄,获取显示在picture上或者是屏幕上的图像都没有区别的.
前者是PICTURE.HDC,后者是GETDC(0)
QXPro 2009-02-27
  • 打赏
  • 举报
回复
为什么不用 IPictureDisp
wap21 2009-02-27
  • 打赏
  • 举报
回复
up
helson 2009-02-27
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 QXPro 的回复:]
为什么不用 IPictureDisp
[/Quote]
怎么使用IPictureDisp,请说说你的建议,最好有代码,谢谢!
Tiger_Zhao 2009-02-26
  • 打赏
  • 举报
回复
下面是 API-Guide 的例子,调用 GetDIBits 后的 bBytes 数组应该就是你要的数据
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0 ' color table in RGBs
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
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
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Dim iBitmap As Long, iDC As Long
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'-> Compile this code for better performance
Dim bi24BitInfo As BITMAPINFO, bBytes() As Byte, Cnt As Long
With bi24BitInfo.bmiHeader
.biBitCount = 24
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(bi24BitInfo.bmiHeader)
.biWidth = 100
.biHeight = 100
End With
ReDim bBytes(1 To bi24BitInfo.bmiHeader.biWidth * bi24BitInfo.bmiHeader.biHeight * 3) As Byte
iDC = CreateCompatibleDC(0)
iBitmap = CreateDIBSection(iDC, bi24BitInfo, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
SelectObject iDC, iBitmap
BitBlt iDC, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, GetDC(0), 0, 0, vbSrcCopy
GetDIBits iDC, iBitmap, 0, bi24BitInfo.bmiHeader.biHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS
For Cnt = LBound(bBytes) To UBound(bBytes)
If bBytes(Cnt) < 50 Then
bBytes(Cnt) = 0
Else
bBytes(Cnt) = bBytes(Cnt) - 50
End If
Next Cnt
SetDIBitsToDevice Me.hdc, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, 0, 0, 0, bi24BitInfo.bmiHeader.biHeight, bBytes(1), bi24BitInfo, DIB_RGB_COLORS
DeleteDC iDC
DeleteObject iBitmap
End Sub
helson2008 2009-02-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chenjl1031 的回复:]
将图像保存到数组中,这个可以参考:
http://topic.csdn.net/u/20080202/15/76d09e72-27ee-4deb-a66a-03518ea2f003.html?1122400373
[/Quote]
你好,你给的例子我看了,还是存在使用picturebox的情况,我不想使用picturebox,请问有什么更好的办法吗?
东方之珠 2009-02-23
  • 打赏
  • 举报
回复
将图像保存到数组中,这个可以参考:
http://topic.csdn.net/u/20080202/15/76d09e72-27ee-4deb-a66a-03518ea2f003.html?1122400373
helson2008 2009-02-21
  • 打赏
  • 举报
回复
大家帮帮忙啊!
helson2008 2009-02-21
  • 打赏
  • 举报
回复
我要用VB实现以下功能: (对问题进行了一些修正)
从屏幕的(x,y)坐标开始得到100*100像素大小内的屏幕的图像数据,然后把这些数据存到一个数组当中,本人用有form的的picturebox已经实现,但是我想把这个功能做成dll,不想带有form窗口,也就是不想使用picturebox,请问如何解决呢,再网上也看了一下,可能用到Createdibsection、CreateDIBSection和bitble函数,现在想请教大家这个dll如何用VB写呢,请给出具体的代码(VB的),能够解决我这个问题的给100分。

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧