Jump to content
Sign in to follow this  

Memory overflow trying to create lots of images

Recommended Posts

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?

Local $sFileMaterialList = "C:\myFile.txt"
Local $sDestinationDir = @ScriptDir & "\Images"
Local $line = 1

$hMaterialList = FileOpen( $sFileMaterialList, 0 )
DirCreate(sDestinationDir )

;create images and exit if EOF
    $sMaterial = FileReadLine ( $hMaterialList , $line )
    If @error = -1 Then
    If stringlen($sMaterial)>0 Then
    $line = $line + 1

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
    ; Clean up resources & shutdown
    _GDIPlus_ImageDispose ($hImage)
    _GDIPlus_ShutDown ()

Share this post

Link to post
Share on other sites


Dispose of each $hBuffer as well.

Add _GDIPlus_GraphicsDispose($hBuffer) to your clean up.


Edited by smashly

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...