Hi,
i have some issues with using gflSaveBitmapIntoMemory in Delphi, better say with freeing memory after that.
....
var Size:integer;
Mem:PGFL_UINT8;
sp: TGFL_SAVE_PARAMS;
e: GFL_ERROR;
FS:TFileStream;
.....
gflGetDefaultSaveParams(sp);
sp.FormatIndex := tiff;
sp.Compression := GFL_LZW;
e := gflSaveBitmapIntoMemory(Mem, @Size, gfl_bmp, sp);
FS.Write(Mem^,Size);
gflMemoryFree(Pointer(Mem));
Is it right ? Probably not, because on gflMemoryFree(Pointer(Mem)); i get exception "Invalid address specified ... " How to free memory after save ?
Thanks.
How to use gflSaveBitmapIntoMemory in Delphi
Moderators: XnTriq, helmut, xnview
-
- Author of XnView
- Posts: 44325
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: How to use gflSaveBitmapIntoMemory in Delphi
I'm not expert in Delphi , but in C here is the code:
Code: Select all
GFL_UINT8* data;
GFL_UINT32 length;
gflSaveBitmapIntoMemory( &data, &length, pBitmap, &save_params );
gflMemoryFree( data );
Pierre.
-
- Posts: 3
- Joined: Wed Nov 12, 2008 9:26 am
So what's the different? Thats exception is catched bay gflMemoryFree, so I see it only in debug mode, but no memory is freed.
When I make a loop ... for example:
used memory still growing. So what's wrong?
When I make a loop ... for example:
Code: Select all
for I := 0 to 500 do begin
e := gflSaveBitmapIntoMemory(Mem, @Size, gfl_bmp, sp);
FS.Write(Mem^,Size);
gflMemoryFree(Pointer(Mem));
end;
-
- Posts: 3
- Joined: Wed Nov 12, 2008 9:26 am
I have found the bug. It's in the LibGfl.pas
Wrong:
Right:
Wrong:
Code: Select all
function gflMemoryRealloc(var Ptr: Pointer; size: GFL_UINT32): Pointer; stdcall;
procedure gflMemoryFree(var Ptr: Pointer); stdcall;
Code: Select all
function gflMemoryRealloc(Ptr: Pointer; size: GFL_UINT32): Pointer; stdcall;
procedure gflMemoryFree(Ptr: Pointer); stdcall;
-
- Author of XnView
- Posts: 44325
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France