AddText fails with 'Error to Alloc Memory'

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

Drovesti
Posts: 1
Joined: Fri May 07, 2004 4:37 pm

AddText fails with 'Error to Alloc Memory'

Post by Drovesti »

When i try to put a simple text label in a tiff file with a dpi 400x400 resolution my program (I MODIFIED THE SAMPLE VB PROGRAM SHIPPED WITH THE SDK) fail with this error in the GFLADDTEXT function:

ERROR TO ALLOC MEMORY.

With different file (200 DPI resolution) the program works well. The only difference that i found into the files is the DPI resolution.

If someone needs the files ask me and i can send it.


ANY IDEAS ???

Code: Select all

Dim GflBitmap As GFL_BITMAP
Dim GflParams As GFL_LOAD_PARAMS
Dim PtrBitmap As Long
Dim GflInfo As GFL_FILE_INFORMATION
Dim File As String
Dim Error As Integer
 
Dim Txt As String
Dim FontName As String
Dim FontSize As Long
Dim FontBold As Boolean
Dim FontItalic As Boolean
Dim FontStrikeOut As Boolean
Dim FontUnderline As Boolean
Dim FontColor As GFL_COLOR
 
gflLibraryInit
gflGetDefaultLoadParams GflParams
 
With GflParams
    .Flags = GFL_LOAD_SKIP_ALPHA Or GFL_LOAD_BY_EXTENSION_ONLY
    .Origin = GFL_BOTTOM_LEFT 'Origin is bottom-left
    .ColorModel = GFL_BGR 'Component order like DIB
    .LinePadding = 4 'Line padding on 4 bytes (32bits)
End With
 
File = App.Path & "\image.jpg"
File = "\\Dev2k1\sviluppo\WALVOIL\images\NonVa_1.png"
Error = gflLoadBitmap(File, PtrBitmap, GflParams, GflInfo) 'Load picture
Me.AutoRedraw = True 'Form must be refreshed
    
    If Error = GFL_NO_ERROR Then 'If no error
        extGetGflBitmapFromPtr PtrBitmap, GflBitmap   'Get the data
                
        Txt = "gflAddText"    'The text...
        FontName = "Verdana"  'The font
        FontSize = "50"       'The size of font
        FontBold = True
        FontItalic = False
        FontStrikeOut = False
        FontUnderline = False
        FontColor.Blue = 0 'Font color
        FontColor.Green = 0
        FontColor.Red = 255
        FontColor.Alpha = 0
        'Add text in bitmap
        Error = gflAddText(GflBitmap, Txt, FontName, 10, 10, FontSize, 0, CByte(FontItalic), CByte(FontBold), CByte(FontStrikeOut), CByte(FontUnderline), CByte(True), FontColor)
        
        extShowBitmapOnDc GflBitmap, Me.hdc 'Display bitmap
        gflFreeBitmapData GflBitmap 'Free bitmap
    End If
 
If Error <> GFL_NO_ERROR Then MsgBox extGetStr(gflGetErrorString(Error)) 'Display a message box
gflLibraryExit 'Quit the library
User avatar
xnview
Author of XnView
Posts: 44926
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: AddText fails with 'Error to Alloc Memory'

Post by xnview »

Drovesti wrote:When i try to put a simple text label in a tiff file with a dpi 400x400 resolution my program (I MODIFIED THE SAMPLE VB PROGRAM SHIPPED WITH THE SDK) fail with this error in the GFLADDTEXT function:

ERROR TO ALLOC MEMORY.

With different file (200 DPI resolution) the program works well. The only difference that i found into the files is the DPI resolution.
Sometimes, AddText can return an error. It's fixed in the next release.
Pierre.
tblack1100
Posts: 4
Joined: Thu Dec 08, 2005 2:22 pm

Similar problem with newest version

Post by tblack1100 »

Hello,

I recently downloaded your gflsdk to see if it could be used to merge groups of tiff files into single files. I also wanted to add a text notation to the bottom of each page. I copied and pasted the code from the addtext example into the merge tiff example. It doesn't return an error on the gflAddText, but does on the gflFileAddPicture function. I'd appreciate any assistance. Thanks!

**** CODE *****
' ------------------------------
' This example use :
' ------------------------------
' gflFileCreate
' gflFileAddPicture
' gflFileClose
' gflGetDefaultSaveParams
' gflGetFormatIndexByName
' gflGetDefaultLoadParams
' gflLoadBitmap
'
' extGetGflBitmapFromPtr
'
' gflLibraryInit
' gflLibraryExit
'
' GFL_LOAD_PARAMS
' GFL_SAVE_PARAMS
' GFL_FILE_INFORMATION
' GFL_BITMAP
' ------------------------------
Option Explicit

Private Sub Form_Load()
Dim LoadParams As GFL_LOAD_PARAMS
Dim SaveParams As GFL_SAVE_PARAMS
Dim Infos As GFL_FILE_INFORMATION
Dim GflBitmap As GFL_BITMAP
Dim PtrBitmap As Long
Dim Ret As Integer
Dim DstFile As String
Dim SrcFile() As String
Dim Count As Long
Dim Ind As Integer
Dim Handle As Long
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim intNum As Integer
Dim Txt As String
Dim FontName As String
Dim FontSize As Long
Dim FontBold As Boolean
Dim FontItalic As Boolean
Dim FontStrikeOut As Boolean
Dim FontUnderline As Boolean
Dim FontColor As GFL_COLOR

Set objFSO = New FileSystemObject
Set objFolder = objFSO.GetFolder("\\iis\ppncache\")

Count = objFolder.Files.Count
ReDim SrcFile(Count - 1)
intNum = 0

For Each objFile In objFolder.Files
SrcFile(intNum) = "\\iis\ppncache\" & objFile.Name
intNum = intNum + 1
Next
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing

DstFile = App.Path & "\image.tif" 'TIFF file to receive picture

'SrcFile(0) = App.Path & "\image.dcm" 'Picture to add
'SrcFile(1) = App.Path & "\image.bmp"
'SrcFile(2) = App.Path & "\image.jpg"
'Count = UBound(SrcFile) + 1

gflLibraryInit 'Initialize the library
gflGetDefaultSaveParams SaveParams 'Get default parameters for saving
SaveParams.FormatIndex = gflGetFormatIndexByName("tiff") 'Get index of TIFF format

Txt = "This is a test!" 'The text...
FontName = "Verdana" 'The font
FontSize = "50" 'The size of font
FontBold = True
FontItalic = False
FontStrikeOut = False
FontUnderline = False
FontColor.Blue = 0 'Font color
FontColor.Green = 0
FontColor.Red = 255

Ret = gflFileCreate(Handle, DstFile, Count, SaveParams) 'Create the TIFF file
If Ret = GFL_NO_ERROR Then 'If no error
Text1.text = Text1.text & "Create " & DstFile & vbCrLf
For Ind = 0 To Count - 1 'For each picture
gflGetDefaultLoadParams LoadParams 'Get default parameters for loading
Ret = gflLoadBitmap(SrcFile(Ind), PtrBitmap, LoadParams, Infos) 'Load the picture
If Ret = GFL_NO_ERROR Then 'If no error
extGetGflBitmapFromPtr PtrBitmap, GflBitmap 'Get data in Gfl_Bitmap
Ret = gflAddText(GflBitmap, Txt, FontName, 10, 10, FontSize, 0, CByte(FontItalic), CByte(FontBold), CByte(FontStrikeOut), CByte(FontUnderline), CByte(True), FontColor)
If Ret = GFL_NO_ERROR Then 'If no error
gflFileAddPicture Handle, GflBitmap 'Add picture on TIFF file
End If
Text1.text = Text1.text & "Adding " & SrcFile(Ind) & vbCrLf
End If
Next
gflFileClose Handle 'Close the TIFF file
Text1.text = Text1.text & "Close the file"
End If

gflLibraryExit 'Quit the library
End Sub