向各位大佬们求助,急急急,批量转换尺寸时遇到的灾难^-^
这段时间需要批量修改图片尺寸,于是就用本网现成的代码,单个转换时没问题,批量转换时就出现‘无内存……’提示,一通出错提示。查看任务管理器,发现可用内存和空闲内存告急,退出软件后,内存数量恢复正常。
后来多次测试后,还是发现还是以下进程的问题,调用一次,内存就下降的历害,不知道怎么释放其运行后不断占用的内存,
代码如下,请各位指导,谢谢
*原图片尺寸改变现有的图片尺寸
*a=resizeimage("c:\temp\37057.jpg","C:\temp\37057_haOK.jpg",1024,768)
*a=resizeimage("c:\temp\37517.jpg","C:\temp\37057_haOK.jpg",0,0)
*WAIT windows (a)
*!* Declare INTEGER ShellExecute IN shell32;
*!* INTEGER hwnd, STRING lpOperation,;
*!* STRING lpFile, STRING lpParameters,;
*!* STRING lpDirectory, INTEGER nShowCmd
*!* = ShellExecute (0, [open], [c:\temp\37517.jpg],[],[], 3) && 原图
*!* =INKEY(2) && 等待2秒钟再查看新图
*!* = ShellExecute (0, [open], [C:\temp\37517_ha.jpg],[],[], 3) && 新图
***768,1365,"c:\temp\37517.jpg","C:\temp\37517_h.jpg"
*******************************************
*算法制作:行者孙(QQ:310727570)
*******************************************
FUNCTION resizeimage &&(pSourceFileNAme as String,pNewFileNAme as String,nWidth as Long,nHeight as long)
LPARAMETERS pSourceFileNAme,pNewFileNAme,nWidth,nHeight
* PRIVATE pSourceFileNAme,pNewFileNAme,nWidth,nHeight
*************************************************************************************
IF FILE(pSourceFileNAme)=.t.
ELSE
pSourceFileNAme=.f.
RETURN .f.
endif
IF nWidth=0 OR nHeight=0 &&&&自动
_Screen.AddObject( 'pic', 'Image' )
_Screen.pic.Picture = pSourceFileNAme
* ? _Screen.pic.Width, _Screen.pic.Height
*op = Createobject("WIA.ImageFile")
*op.LoadFile (pSourceFileNAme)
*!* op = CREATEOBJECT("Image")
*!* op.picture=pSourceFileNAme
LOCAL ow,oh,min_cc &&&&&&&&&&&&&&&&&&&&&&&&& min_cs :最小的那个尺寸
ow=_Screen.pic.Width
oh=_Screen.pic.Height
_Screen.RemoveObject( 'pic' )
min_cc=600 &&&&&最小尺寸
IF ow>min_cc AND oh>min_cc
nHeight=IIF(ow>oh,min_cc,round(min_cc*oh/ow,0))
nWidth=IIF(ow>oh,ROUND(min_cc*ow/oh,0),min_cc)
ELSE
IF OW<150 OR OH<150
MESSAGEBOX('转化程序出问T'+pSourceFileNAme,16,'提示')
*WAIT windows STR(nHeight)+'h/w'+STR(nWidth)
WAIT windows STR(oh)+'h/w'+STR(ow)
pSourceFileNAme=.f.
RETURN .f.
ENDIF
nHeight=oh
nWidth=ow
ENDIF
*WAIT windows STR(nWidth)+'w/h:'+STR(nHeight)
RELEASE op
ENDIF
*****************************************************************************************8
DECLARE INTEGER GdiplusStartup IN gdiplus.DLL INTEGER @token, STRING @INPUT, INTEGER OUTPUT
LOCAL hToken, cInput
hToken = 0
cInput = PADR(CHR(1), 16, CHR(0))
GdiplusStartup(@hToken, @cInput, 0)
DECLARE INTEGER GdipLoadImageFromFile IN gdiplus.DLL STRING wFilename, INTEGER @nImage
LOCAL nImage
nImage = 0
IF GdipLoadImageFromFile(STRCONV(pSourceFileNAme + CHR(0), 5), @nImage)=0
ELSE
pSourceFileNAme=.f.
RETURN .f.
ENDIF
#DEFINE GDIPLUS_PIXELFORMAT_32bppARGB 0x0026200A
DECLARE INTEGER GdipCreateBitmapFromScan0 IN gdiplus.DLL ;
INTEGER nWidth, INTEGER nHeight, INTEGER nStride;
, INTEGER nPixelFormat ;
, STRING @ cScan0, INTEGER @ nImage
LOCAL nBitmap, nWidth, nHeight, nX, nY
nBitmap = 0
nX = 0
nY = 0
IF GdipCreateBitmapFromScan0(nWidth, nHeight, 0, GDIPLUS_PIXELFORMAT_32bppARGB, 0, @nBitmap)=0
ELSE
pSourceFileNAme=.f.
RETURN .f.
ENDIF
DECLARE INTEGER GdipGetImageGraphicsContext IN gdiplus.DLL ;
INTEGER nImage, INTEGER @ nGraphics
LOCAL nGraphics
nGraphics = 0
IF GdipGetImageGraphicsContext(nBitmap, @nGraphics)=0
ELSE
pSourceFileNAme=.f.
RETURN .f.
ENDIF
DECLARE INTEGER GdipDrawImageRect IN gdiplus.DLL ;
INTEGER nGraphics, INTEGER nImage, SINGLE,SINGLE,SINGLE,SINGLE
GdipDrawImageRect(nGraphics, nImage, nX, nY, nWidth, nHeight)
LOCAL lcEncoder
lcEncoder = REPLICATE(CHR(0),16)
DECLARE INTEGER CLSIDFromString IN ole32 STRING lpsz, STRING @pclsid
CLSIDFromString(STRCONV("{557CF401-1A04-11D3-9A73-0000F81EF32E}" + CHR(0), 5), @lcEncoder)
DECLARE INTEGER GdipSaveImageToFile IN gdiplus.DLL ;
INTEGER nImage, STRING wFilename, STRING qEncoder, INTEGER nEncoderParamsPtr
ERASE (pNewFileNAme)
DECLARE Long GdipDisposeImage IN Gdiplus.dll Long nativeImage
GdipDisposeImage(nImage)
GdipSaveImageToFile (nBitmap, STRCONV(pNewFileNAme,5) + CHR(0), lcEncoder, 0)
DECLARE INTEGER GdiplusShutdown IN gdiplus INTEGER token
GdiplusShutdown(hToken)
CLEAR DLLS
#UNDEF GDIPLUS_PIXELFORMAT_32bppARGB
pSourceFileNAme=.t.
RETURN .t.
ENDFUNC
[此贴子已经被作者于2023-2-1 03:41编辑过]