vfp8,表单init中用一段代码,是执行img_resize.prg,把大图转成小图,转换完成后我想删除原来的大图,但vfp显示“不能存取文件”,该如何在转换完成后解除对原文件的占用?
谢谢!
------解决方案--------------------------------------------------------
把 resizeimage() 改为如下:红色部分为我后加入的代码
Function resizeimage(pSourceFileNAme As String,pNewFileNAme As String,nHeight As Long)
Declare Integer GdiplusStartup In GDIPlus;
INTEGER @token, String @Input, Integer Output
Declare Integer GdipGetImageHeight In GDIPlus;
INTEGER img,;
INTEGER @ imgheight
Declare Integer GdipGetImageWidth In GDIPlus;
INTEGER img,Integer @ imgwidth
Declare Integer GdipLoadImageFromFile In GDIPlus.Dll ;
STRING wFilename, Integer @nImage
Declare Integer GdipDrawImageRect In GDIPlus.Dll ;
INTEGER nGraphics, Integer nImage, Single,Single,Single,Single
Declare Integer GdipCreateBitmapFromScan0 In GDIPlus.Dll ;
INTEGER nWidth, Integer nHeight, Integer nStride,;
INTEGER nPixelFormat,String @ cScan0, Integer @ nImage
Declare Integer GdipGetImageGraphicsContext In GDIPlus.Dll ;
INTEGER nImage, Integer @ nGraphics
Declare Integer CLSIDFromString In ole32 String lpsz, String @pclsid
Declare Integer GdipSaveImageToFile In GDIPlus.Dll ;
INTEGER nImage, String wFilename, String qEncoder, Integer nEncoderParamsPtr
Declare Integer GdiplusShutdown In GDIPlus Integer token
Declare Long GdipDisposeImage In GDIPlus.Dll Long nativeImage
#Define GDIPLUS_PIXELFORMAT_32bppARGB 0x0026200A
Store 0 To hToken,nImage,nGraphics,nBitmap,nWidth,uWidth,uHeight
cInput = Padr(Chr(1), 16, Chr(0))
GdiplusStartup(@hToken, @cInput, 0)
GdipLoadImageFromFile(Strconv(pSourceFileNAme+Chr(0),5),@nImage)
GdipGetImageHeight(nImage,@uHeight)
GdipGetImageWidth(nImage,@uWidth)
nWidth=uWidth*(nHeight/uHeight)&&同比变比
GdipCreateBitmapFromScan0(nWidth,nHeight,0,GDIPLUS_PIXELFORMAT_32bppARGB, 0, @nBitmap)
GdipGetImageGraphicsContext (nBitmap, @nGraphics)
GdipDrawImageRect(nGraphics,nImage,0,0,nWidth, nHeight)
lcEncoder = Replicate(Chr(0),16)
CLSIDFromString(Strconv("{557CF401-1A04-11D3-9A73-0000F81EF32E}"+Chr(0),5),@lcEncoder)
GdipSaveImageToFile (nBitmap, Strconv(pNewFileNAme,5)+Chr(0),lcEncoder,0)
GdipDisposeImage(nImage)
GdiplusShutdown(hToken)
Endfunc