vfp中如何把剪贴板中的图像保存为指定路径的BMP格式文件
vfp中如何把剪贴板中的图像保存为指定路径的BMP格式文件
[解决办法]
转自 dkfdtf 版主
SaveScreen('c:\test.bmp')
Function SaveScreen( tcFile )
#Define CF_BITMAP 2
#Define VK_SNAPSHOT 0x2C
#Define KEYEVENTF_KEYUP 0x0002
Local cFileExtName, cEncoder, iInputBuf, iResult
Local hBitmap, hToken, hGdipBitmap
m.cFileExtName = Lower( Justext( m.tcFile ))
decl_api()
m.iResult = -1
If ( 0 != OpenClipboard( 0 ))
m.hBitmap = GetClipboardData( CF_BITMAP )
If ( 0 != m.hBitmap )
m.hToken = 0
m.iInputBuf = 0h01 + Replicate( Chr(0),15 )
If ( 0 == GdiplusStartup( @ m.hToken, @ m.iInputBuf, 0 ))
m.hGdipBitmap = 0
If ( 0 == GdipCreateBitmapFromHBITMAP( ;
m.hBitmap, 0, @ m.hGdipBitmap ))
m.cEncoder = Icase( ;
'jpg' == m.cFileExtName, 0h01, ;
'gif' == m.cFileExtName, 0h02, ;
'tif' == m.cFileExtName, 0h05, ;
'png' == m.cFileExtName, 0h06, 0h00 ) ;
+ 0hF47C55041AD3119A730000F81EF32E
m.iResult = GdipSaveImageToFile( ;
m.hGdipBitmap, ;
STRCONV( m.tcFile+Chr(0), 5 ), ;
m.cEncoder, 0 )
GdipDisposeImage( m.hGdipBitmap )
Endif
GdiplusShutdown( m.hToken )
Endif
EmptyClipboard()
CloseClipboard()
Endif
Endif
Return ( 0 == m.iResult )
Endfunc
Function decl_api
Declare Long keybd_event In WIN32API ;
Long bVk, Long bScan, Long dwFlags, Long dwExtraInfo
Declare Long OpenClipboard In WIN32API ;
Long hWndNewOwner
Declare Long EmptyClipboard In WIN32API
Declare Long CloseClipboard In WIN32API
Declare Long GetClipboardData In WIN32API ;
Long uFormat
Declare Long GdiplusStartup In GDIPlus ;
Long @ token, String @ inputbuf, Long @ outputbuf
Declare Long GdiplusShutdown In GDIPlus ;
Long token
Declare Long GdipCreateBitmapFromHBITMAP In GDIPlus ;
Long hbitmap, Long hpalette, Long @ hGpBitmap
Declare Long GdipDisposeImage In GDIPlus ;
Long Image
Declare Long GdipSaveImageToFile In GDIPlus ;
Long nImage, String FileName, ;
String clsIdEncoder, Long encoderParams
Endfunc