Page 1 of 1

gflLoadBitmapFromMemory Error

Posted: Fri Dec 21, 2007 8:18 pm
by tdemarsh
I'm trying to load TIFFs using the gflLoadBitmapFromMemory procedure. When I do, I get an "Unknown Format" error. The procedure's result value is 6.

When using gflLoadBitmap (from a file), it works fine.

I'm using Delphi 7, and the GFL SDK I downloaded today (version 2.80).

I've tried setting the LinePadding to a value of 2 (TIFF index?).

My code, which is mostly copied from the Delphi demo, but changed from loading from a file to loading from a TFileStream:

Code: Select all

procedure TForm2.Button4Click(Sender: TObject);
var
  finfo: TGFL_FILE_INFORMATION;
  lp: TGFL_LOAD_PARAMS;
  gfl_bmp: PGFL_BITMAP;
  e: GFL_ERROR;
  y : Integer;
  LineSrc: Pointer;
  LineDest: Pointer;
  pal: PLogPalette;
  i, bpp: Integer;
  Arect: TRect;
  NewPalette: hPalette;
  TIFStream : TFileStream;
begin
  TIFStream := TFileStream.Create('c:\t\6336579280-1.tif', fmOpenRead or fmShareDenyWrite);
  try
    if TIFStream.Size<=0 then
      exit;

    gflEnableLZW(GFL_TRUE);

    // Load GFL Bitmap
    gflGetDefaultLoadParams(lp);
    lp.ColorModel := GFL_BGR;
    lp.LinePadding := 4;

    e := gflLoadBitmapFromMemory(Pointer(TIFStream), TIFStream.Size, gfl_bmp, lp, finfo);
    if (e <> gfl_no_error) then
      raise Exception.Create('Stream not readable: ' + string(gflGetErrorString(e)));
  finally
    TIFStream.Free;
  end;
end;
Any suggestions would be greatly appreciated.

Posted: Fri Dec 21, 2007 9:12 pm
by tdemarsh
Found a solution. Changed the TFileStream to a TMemoryStream, and passed the Memory property of the TMemoryStream as the first parameter.

Code: Select all

procedure TForm2.Button4Click(Sender: TObject);
var
  finfo: TGFL_FILE_INFORMATION;
  lp: TGFL_LOAD_PARAMS;
  gfl_bmp: PGFL_BITMAP;
  e: GFL_ERROR;
  y : Integer;
  LineSrc: Pointer;
  LineDest: Pointer;
  pal: PLogPalette;
  i, bpp: Integer;
  Arect: TRect;
  NewPalette: hPalette;
  TIFStream : TMemoryStream;
begin
  TIFStream := TMemoryStream.Create;
  try
    TIFStream.LoadFromFile('c:\t\6336579280-1.tif');

    if TIFStream.Size<=0 then
      exit;

    gflEnableLZW(GFL_TRUE);

    // Load GFL Bitmap
    gflGetDefaultLoadParams(lp);
    lp.ColorModel := GFL_BGR;
    lp.LinePadding := 4;

    e := gflLoadBitmapFromMemory(TIFStream.Memory, TIFStream.Size, gfl_bmp, lp, finfo);
    if (e <> gfl_no_error) then
      raise Exception.Create('Stream not readable: ' + string(gflGetErrorString(e)));
  finally
    TIFStream.Free;
  end;
end;