标题:VFP9+WIN10下将剪贴板的图片内容另存为指定.png文件不成功
只看楼主
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
结帖率:0
已结贴  问题点数:20 回复次数:11 
VFP9+WIN10下将剪贴板的图片内容另存为指定.png文件不成功
各位好!希望VFP9+WIN10下将剪贴板的图片内容另存为指定.png文件,但不成功。
下面是网上找的代码
DECLARE INTEGER GdipSavelmageToFile IN gdiplus.DLL ;
        INTEGER nlmage,;
        STRING wFilename,;
        STRING qEncoder,;
        STring @nEncoderParamsPtr
DECLARE INTEGER CLSIDFromString IN ole32 STRINGIpsz,STRING @pclsid
DECLARE INTEGER GdipLoadlmageFromFile IN gdiplus.DLL;
        STRING wFilename, INTEGER @nlmage
DECLARE INTEGER StrDup IN shlwapi STRING @lpsz
LOCAL nlmage as Integer
pSourceFileNAme='d:\无标题1.png'
pNewFileNAme='d:\无标题2.png'
clnput = PADR(CHR(1),16,CHR(0))
&&GdipLoadlmageFromFile(STRCONV(pSourceFileNAme+CHR(0),5),@nlmage)
GUID_FormatJPG="{557CF401-1A04-11D3-9A73-0000F81EF32E}"
IcEncode=REPLICATE(CHR(0),16)
STRCONV_loc=STRCONV(GUID_FormatJPG+CHR(0),5)
CLSIDFromString(STRCONV_loc,@IcEncode)&&这里定义保存后的图像格式为 JPG
CLSIDFromString(STRCONV_loc)
IcGuid = REPLICATE(CHR(0),16)
GUID_Quality="{1d5be4b5-fa4a-452d-9cdd-5db35105e7eb}"&&对图像质量进行操作
CLSIDFromString(STRCONV(GUID_Quality+CHR(0),5),@IcGuid)
Quality=50&&图像质量值设置
QualityStr=BINTOC(Quality,'4rs')
ValuePtr=StrDup(@QualityStr)&&得到图像质量设置值的内存地址
EncoderParameter=IcGuid+BINTOC(1,'4rs')+BINTOC(4,'4rs')+BINTOC(ValuePtr,'4rs')
EncoderParameters=bintoc(1,'4rs')+EncoderParameter
GdipSavelmageToFile(nlmage,STRCONV(pNewFileNAme+CHR(0),5),IcEncode,@EncoderParameters)
MESSAGEBOX("保存到 d:\无标题2.png")
搜索更多相关主题的帖子: 图像 STRING png VFP9 INTEGER 
2022-03-27 10:36
sych
Rank: 3Rank: 3
等 级:论坛游侠
威 望:6
帖 子:179
专家分:183
注 册:2019-10-11
得分:5 
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
    MESSAGEBOX("剪贴板中没有图像",64,"温馨提示")
else
    IF OpenClipboard(0)=0
        MESSAGEBOX("剪贴板打开失败",64,"温馨提示")
    else
        lcOutputFile="_paster.png"
        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_BMP=0h00F47C55041AD3119A730000F81EF32E
        GdipSaveImageToFile(ubitmap,STRCONV(lcOutputFile+CHR(0),5),qEncoderClsID_BMP,null)
        GdipDisposeImage(ubitmap)
        GdiplusShutdown(m.hToken)
        closehandle(hBitmap)
        CloseClipboard()
    endif
endif
2022-03-27 11:13
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
得分:0 
谢谢!测试成功!
2022-03-27 11:21
sych
Rank: 3Rank: 3
等 级:论坛游侠
威 望:6
帖 子:179
专家分:183
注 册:2019-10-11
得分:0 
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
    MESSAGEBOX("剪贴板中没有图像",64,"温馨提示")
else
    IF OpenClipboard(0)=0
        MESSAGEBOX("剪贴板打开失败",64,"温馨提示")
    else
        lcOutputFile="d:\test.jpg"
        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_BMP=0h01F47C55041AD3119A730000F81EF32E
        GdipSaveImageToFile(ubitmap,STRCONV(lcOutputFile+CHR(0),5),qEncoderClsID_BMP,null)
        GdipDisposeImage(ubitmap)
        GdiplusShutdown(m.hToken)
        closehandle(hBitmap)
        CloseClipboard()
    endif
endif
2022-03-27 11:24
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:5 
0h01F47C55041AD3119A730000F81EF32E 是 BMP
0h06F47C55041AD3119A730000F81EF32E 是 PNG
2022-03-27 11:29
laowan001
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:54
帖 子:802
专家分:1914
注 册:2015-12-30
得分:5 
这是我平常用的,试试看。代码是在网上找的,感谢原作者
程序代码:
FUNCTION saveclipimage
LPARAMETERS szOutputFile
****************************************
* 保存剪贴板里的图片
* szOutputFile:输入文件名,全路径
****************************************

#DEFINE CF_BITMAP    2
DECLARE LONG IsClipboardFormatAvailable  IN User32 LONG
DECLARE LONG OpenClipboard               IN User32 LONG
DECLARE LONG CloseClipboard              IN User32
DECLARE LONG GetClipboardData            IN User32 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 GdipDisposeImage            IN gdiplus LONG
DECLARE LONG GdipSaveImageToFile         IN gdiplus LONG, STRING@, STRING@, LONG

IF IsClipboardFormatAvailable(CF_BITMAP) == 0
    MESSAGEBOX('剪贴板里没有图片',0+64,'系统提示')
    RETURN .F.
ENDIF
IF OpenClipboard(0) == 0
    RETURN .F.
ENDIF
LOCAL dhClipBmp
dhClipBmp = GetClipboardData(CF_BITMAP)
IF dhClipBmp == 0
    CloseClipboard()
    MESSAGEBOX('剪贴板里没有图片',0+64,'系统提示')
    RETURN .F.
ENDIF
LOCAL stGSI, lpGDI, jpgGUID, dhBitmap
stGSI = 0h01000000000000000000000000000000
lpGDI = 0
GdiplusStartup(@lpGDI, @stGSI, 0)
jpgGUID  = 0h01F47C55041AD3119A730000F81EF32E
dhBitmap = 0
GdipCreateBitmapFromHBITMAP(dhClipBmp, 2, @dhBitmap)
GdipSaveImageToFile(dhBitmap, STRCONV(szOutputFile + 0h00, 5), @jpgGUID, 0)
GdipDisposeImage(dhBitmap)
GdiplusShutdown(lpGDI)
CloseClipboard()
RETURN .T.
2022-03-27 11:31
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
得分:0 
以下是引用吹水佬在2022-3-27 11:29:40的发言:

0h01F47C55041AD3119A730000F81EF32E 是 BMP
0h06F47C55041AD3119A730000F81EF32E 是 PNG

网上收集的这段代码如何对照理解?
#define CLSID_BMP     "{557CF400-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_JPEG    "{557CF401-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_GIF     "{557CF402-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_TIFF    "{557CF405-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_PNG     "{557CF406-1A04-11D3-9A73-0000F81EF32E}"
2022-03-27 11:34
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
得分:0 
以下是引用吹水佬在2022-3-27 11:29:40的发言:

0h01F47C55041AD3119A730000F81EF32E 是 BMP
0h06F47C55041AD3119A730000F81EF32E 是 PNG

求其它几种图片类型
JPG
GIF
TIFF
谢谢
2022-03-27 11:38
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
回复 8楼 shschy
7楼的就是,那个二进制字符串差别在第一个字节
2022-03-27 13:54
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
得分:0 
差别好像不仅一个字节,还是没有发现规律,网上也搜集一些信息。
希望能补充完整,谢谢
0
1  BMP
2  GIF
3
4
5  TIFF
6  PNG

有完整介绍链接吗?
  
网上收集的这段代码如何对照理解?
#define CLSID_BMP     "{557CF400-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_JPEG    "{557CF401-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_GIF     "{557CF402-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_TIFF    "{557CF405-1A04-11D3-9A73-0000F81EF32E}"
#define CLSID_PNG     "{557CF406-1A04-11D3-9A73-0000F81EF32E}"

lqEncoderClsID_BMP=0h00F47C55041AD3119A730000F81EF32E &&BMP
lqEncoderClsID_JPG=0h01F47C55041AD3119A730000F81EF32E &&JPG
lqEncoderCLsID_GIF=0h02F47C55041AD3119A730000F81EF32E &&GIF
lqEncoderClsID_TIF=0h05F47C55041AD3119A730000F81EF32E &&TIF
lqEncoderclsID_PNG=0h06F47C55041AD3119A730000F81EF32E &&PNG
                   0h01F47C55041AD3119A730000F81EF32E 是 BMP
0h06F47C55041AD3119A730000F81EF32E 是 PNG
提取比较如下-----
0h01F47C55041AD311-9A73-0000F81EF32E 是 BMP
557CF400-1A04-11D3-9A73-0000F81EF32E
2022-03-27 16:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508672-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031074 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved