简单试了一下,灰度无效?
程序代码:
**
** 屏幕截图
**
DECLARE long GetDC IN user32 long
DECLARE long ReleaseDC IN user32 long,long
DECLARE long CreateCompatibleDC IN gdi32 long
DECLARE long DeleteDC IN gdi32 long
DECLARE long CreateCompatibleBitmap IN gdi32 long,long,long
DECLARE long SelectObject IN gdi32 long,long
DECLARE long DeleteObject IN gdi32 long
DECLARE long BitBlt IN gdi32 long,long,long,long,long,long,long,long,long
DECLARE long GdiplusStartup IN gdiplus long@,string@,long
DECLARE long GdiplusShutdown IN gdiplus long
DECLARE long GdipCreateBitmapFromHBITMAP IN gdiplus long,long,long@
DECLARE long GdipCreateBitmapFromScan0 IN gdiplus long,long,long,long,string@,long@
DECLARE long GdipGetImageGraphicsContext IN gdiplus long, long@
DECLARE long GdipDrawImageRectI IN gdiplus long, long, long, long, long, long
DECLARE long GdipSaveImageToFile IN gdiplus long,string,string,long
DECLARE long GdipDisposeImage IN gdiplus long
DECLARE long GdipDeleteGraphics IN gdiplus long
** Gdipluspixelformats.h
#define PixelFormat1bppIndexed 0x030101 &&每像素1位,进行索引。
#define PixelFormat4bppIndexed 0x030402 &&每像素4位,进行索引。
#define PixelFormat8bppIndexed 0x030803 &&每像素8位,进行索引。
#define PixelFormat16bppGrayScale 0x101004 &&每像素16位灰度。
#define PixelFormat16bppRGB555 0x021005 &&每像素16位;每个5位用于红色,绿色和蓝色组件。剩余的位不被使用。
#define PixelFormat16bppRGB565 0x021006 &&每像素16位;红色分量使用5位,绿色分量使用6位,蓝色分量使用5位。
#define PixelFormat16bppARGB1555 0x061007 &&每像素16位;1位用于alpha分量,每个5位用于红色,绿色和蓝色分量。
#define PixelFormat24bppRGB 0x021808 &&每像素24位;每个8位用于红色,绿色和蓝色组件。
#define PixelFormat32bppRGB 0x022009 &&每像素32位;每个8位用于红色,绿色和蓝色组件。剩余的8位不被使用。
#define PixelFormat32bppARGB 0x26200A &&每像素32位;每个8位用于alpha,red,green和blue组件。
#define PixelFormat32bppPARGB 0x0E200B &&每像素32位;每个8位用于alpha,red,green和blue组件。红色,绿色和蓝色组件根据Alpha组件预乘。
#define PixelFormat48bppRGB 0x10300C &&每像素48位;红色,绿色和蓝色组件都使用16位。
#define PixelFormat64bppARGB 0x34400D &&每像素64位;16位用于alpha,red,green和blue组件。
#define PixelFormat64bppPARGB 0x1C4000E &&每像素64位;16位用于alpha,red,green和blue组件。红色,绿色和蓝色组件根据Alpha组件预乘。
* 初始化GDI
stGSI = 0h01000000000000000000000000000000
lpGDI = 0
GdiplusStartup(@lpGDI, @stGSI, 0)
screenshot(0, "d:\temp\tmp_黑白.bmp", 0, 0, 1000, 500, PixelFormat1bppIndexed)
screenshot(0, "d:\temp\tmp_灰度.bmp", 0, 0, 1000, 500, PixelFormat16bppGrayScale)
screenshot(0, "d:\temp\tmp_彩色.bmp", 0, 0, 1000, 500, PixelFormat32bppARGB)
MESSAGEBOX("截图完成")
GdiplusShutdown(lpGDI)
CLEAR DLLS
RETURN
FUNCTION screenshot(hWnd, outFile, X, Y, nWidth, nHeight, nPixelFormat)
IF !DIRECTORY(JUSTPATH(outFile))
MESSAGEBOX("无效的输出文件路径")
RETURN .F.
ENDIF
* 图像GUID
LOCAL cExt, GUID
cExt = LOWER(JUSTEXT(outFile))
GUID = ICASE(cExt == "bmp", 0h00,;
cExt == "jpg", 0h01,;
cExt == "gif", 0h02,;
cExt == "tif", 0h05,;
cExt == "png", 0h06, "")
IF ("" == GUID)
MESSAGEBOX("无效的输出文件名")
RETURN .F.
ENDIF
GUID = GUID + 0hF47C55041AD3119A730000F81EF32E
* 获取图像设备句柄
LOCAL hDC
hDC = GetDC(hWnd)
IF (hDC == 0)
MESSAGEBOX("获取图像设备句柄失败")
RETURN .F.
ENDIF
* 获取截图设备句柄
LOCAL hppDC, hBitmap, pBitmap
hppDC = CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight)
* 获取截图
SelectObject(hppDC, hBitmap)
BitBlt(hppDC, 0, 0, nWidth, nHeight, hDC, X, Y, 0xCC0020) && SRCCOPY
pBitmap = 0
GdipCreateBitmapFromHBITMAP(hBitmap, 2, @pBitmap)
* 转换格式
pBitmapScan = 0
GdipCreateBitmapFromScan0(nWidth, nHeight, 0, nPixelFormat, 0, @pBitmapScan)
pGraphics = 0
GdipGetImageGraphicsContext(pBitmapScan, @pGraphics)
GdipDrawImageRectI(pGraphics, pBitmap, 0, 0, nWidth, nHeight)
* 保存截图
outFile = STRCONV(outFile + 0h00, 5)
GdipSaveImageToFile(pBitmapScan, outFile, GUID, 0)
* 释放资源
GdipDeleteGraphics(pGraphics)
GdipDisposeImage(pBitmapScan)
GdipDisposeImage(pBitmap)
DeleteObject(hBitmap)
DeleteDC(hppDC)
ReleaseDC(hWnd, hDC)
RETURN .T.
ENDFUNC