matlakala 0 Posted August 15, 2011 Hi Everyone! Couldn't find a solution in the forum. Now I'm asking... I'm trying to make a script that reads lines from a text file and creates images out of each line. The text file can contain 50.000 lines and more. For each line an image will be created. Each image contains the content of this line. Dispose sits inside the loop. First I used _GDIPlus_ImageLoadFromFile and connected functions inside a while loop. After 3000 images, though, the application crashed due to a memory overflow. In another try I had _GDIPlus_ImageLoadFromFile outside the loop but then the second image contained the text lines from the first image and the third from the second and the first and so on. Can someone please help me with this? expandcollapse popup[...] Local $sFileMaterialList = "C:\myFile.txt" Local $sDestinationDir = @ScriptDir & "\Images" Local $line = 1 $hMaterialList = FileOpen( $sFileMaterialList, 0 ) DirCreate(sDestinationDir ) ;create images and exit if EOF While(1) $sMaterial = FileReadLine ( $hMaterialList , $line ) If @error = -1 Then ExitLoop EndIf If stringlen($sMaterial)>0 Then createImage($sMaterial) EndIf $line = $line + 1 WEnd [...] Func createImage($sMaterial) _GDIPlus_Startup () $hImage = _GDIPlus_ImageLoadFromFile ($sBaseImg) $hBuffer = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsDrawString ($hBuffer, $sMaterial, 20, 20, "Arial", 30 ) ; Save image to file If Not _GDIPlus_ImageSaveToFile ($hImage, $sDestinationDir & "\" & $sMaterial & "." & $sFileExtension) Then FileWriteLine(@scriptdir & "\" & $sFileMaterialError, $sMaterial) $err = True EndIf ; Clean up resources & shutdown _GDIPlus_ImageDispose ($hImage) _GDIPlus_ShutDown () EndFunc Share this post Link to post Share on other sites
smashly 12 Posted August 15, 2011 (edited) Hi, Dispose of each $hBuffer as well. Add _GDIPlus_GraphicsDispose($hBuffer) to your clean up. Cheers Edited August 15, 2011 by smashly Share this post Link to post Share on other sites
matlakala 0 Posted August 15, 2011 Argh! That was just too simple. Thanks man. Thanks for the rapid response and the solution. It's working fine now. Share this post Link to post Share on other sites