VFP循环调用截屏程序和另存为程序,会出现图片漏拷贝,尝试加大间隔等待时间,无效
需要:要将某个listbox中列出的JPG文件部分提取,(提取老工卡的照片区域)方法:遍历listbox数据,依次显示对应JPG,再循环调用 command截屏至粘贴板.click
command另存为.click
问题:读取文件夹(Adir()结果到listbox)里图片少时,都能截取保存到新文件,
文件夹里文件多时,50张以上,常会发生无法保存下来。
因为目录下多文件依次操作,找不到原因。现在只能人工查。
人工遍历检查时发现少文件,点按钮调用上面的截屏至粘贴板.click和另存为.click
需求:1)产生原因不知道,希望解决。2)有直接剪贴到粘贴板并同时存储的合并程序吗,因为上面两段代码合并困难。
谢谢!
下面为部分截屏至粘贴板,保存为command截屏至粘贴板.click
DECLARE long GetDC IN user32 long
DECLARE long ReleaseDC IN user32 long,long
DECLARE long OpenClipboard IN user32 long
DECLARE long EmptyClipboard IN user32
DECLARE long CloseClipboard IN user32
DECLARE long SetClipboardData 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
LOCAL nX, nY, nWidth, nHeight, hDC, pDC, hBitmap
nX = thisform.shape1.left+1 &&0
nY = thisform.shape1.top+1 &&0
nWidth = thisform.shape1.width-1
nHeight = thisform.shape1.height-1
hDC = GetDC(thisform.hWnd)
pDC = CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight)
SelectObject(pDC, hBitmap)
BitBlt(pDC, 0, 0, nWidth, nHeight, hDC, nX, nY, 0xCC0020) && SRCCOPY
IF OpenClipboard(0) == 0
MESSAGEBOX("打开剪贴板失败")
RETURN
ENDIF
EmptyClipboard()
SetClipboardData(2, hBitmap) &&CF_BITMAP
CloseClipboard()
WAIT windows "当前第"+STR(ii_pub)+"个"+CHR(13)+"图像装入剪贴板" nowait
PUBLIC outfile_loc_pub
outfile_loc_pub=ALLTRIM(thisform.text_ZHML.Value)+ALLTRIM(thisform.list2.Value)
outfile_loc_pub=STRTRAN(outfile_loc_pub,"拷贝","截取")
&&DeleteObject(hBitmap)
DeleteDC(pDC)
ReleaseDC(thisform.hWnd, hDC)
下面为部分将粘贴板内容另存为指定jpg,保存为command另存为.click
DECLARE INTEGER GetClipboardData IN win32api INTEGER
DECLARE INTEGER OpenClipboard IN win32api INTEGER
DECLARE INTEGER CloseClipboard IN win32api
DECLARE LONG IsClipboardFormatAvailable IN user32 LONG
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
Declare Long GdiplusShutdown in GdiPlus Long token
Declare Long GdiplusStartup in GdiPlus Long @ token, String @ input, Long @ output
DECLARE INTEGER GdipCreateBitmapFromHBITMAP in GdiPlus.dll INTEGER, INTEGER, INTEGER @
DECLARE INTEGER GdipSaveImageToFile in GdiPlus.dll INTEGER,String,String @,String @
DECLARE LONG GdipDisposeImage IN GDIPLUS LONG nImage
*查剪贴板
IF IsClipboardFormatAvailable(2)=0
WAIT windows "剪贴板中没有图像" nowait
else
IF OpenClipboard(0)=0
WAIT windows "当前第"+STR(ii_pub)+"个"+CHR(13)+"剪贴板打开失败" nowait
else
PUBLIC outfile_loc_pub
WAIT windows "当前第"+STR(ii_pub)+"个"+CHR(13)+outfile_loc_pub nowait
lcOutputFile="&outfile_loc_pub"
hBitmap = GetClipboardData(2) &&CF_BITMAP=2
hToken=0
cInput = PADR(CHR(1), 16, CHR(0))
GdiplusStartup(@hToken, @cInput, 0)
ubitmap=0
GdipCreateBitmapFromHBITMAP(hBitmap,2,@ubitmap)
qEncoderClsID_PNG=0h01F47C55041AD3119A730000F81EF32E
GdipSaveImageToFile(ubitmap,STRCONV(lcOutputFile+CHR(0),5),qEncoderClsID_PNG,null)
GdipDisposeImage(ubitmap)
GdiplusShutdown(m.hToken)
closehandle(hBitmap)
CloseClipboard()
WAIT windows "当前第"+STR(ii_pub,8)+"个"+CHR(13)+"截屏保存到"+CHR(13)+"&lcOutputFile" nowait
&&CREATE TABLE jqtpjc_loc (序号 C(08),源图名 c(80),操作 c(4),截图片 c(80),结果 c(4))
SELECT jqtpjc_loc
UPDATE jqtpjc_loc SET 截图片="&lcOutputFile",结果="保存" WHERE 序号=STR(ii_pub,8)
IF !FILE("&lcOutputFile")
MESSAGEBOX("&lcOutputFile"+CHR(13)+"没生成")
ELSE
endif
endif
ENDIF
RETURN .t.
&&差别在第4个字符