Page 1 of 1

GFL -> GDI+

Posted: Sun Oct 09, 2005 9:57 am
by RIMMER
Hi. I'm workin on my graduate project. It's a painting app, based on GDI+ library of Microsoft. I decided to add import/export feature formats with GFL lib, but I experince problems with converting GFL_BITMAP to TGPBitmap. Can anyone help me?

Re: GFL -> GDI+

Posted: Sun Oct 09, 2005 12:33 pm
by xnview
RIMMER wrote:Hi. I'm workin on my graduate project. It's a painting app, based on GDI+ library of Microsoft. I decided to add import/export feature formats with GFL lib, but I experince problems with converting GFL_BITMAP to TGPBitmap. Can anyone help me?
You can use ConvertBitmapToDIB or HBmp, i'm sure that in your TGPBitmap you have a method to use a HBITMAP

Re: GFL -> GDI+

Posted: Sun Oct 09, 2005 7:50 pm
by Guest
xnview wrote:You can use ConvertBitmapToDIB or HBmp, i'm sure that in your TGPBitmap you have a method to use a HBITMAP
For some reasons it didn't work fine for me. This is what i do now:

Code: Select all

function CreateGPBitmapMultipageGFL(FileName: string; PageNumber: Cardinal; var GFLError: Smallint):TGPBitmap;
var
  finfo: TGFL_FILE_INFORMATION;
  lp: TGFL_LOAD_PARAMS;
  gfl_bmp: PGFL_BITMAP;
  gpBitmapData: TBitmapData;
  lngth: Cardinal;
begin
  gflGetDefaultLoadParams(lp);
  lp.ColorModel := GFL_BGRA;
  lp.Flags := GFL_LOAD_FORCE_COLOR_MODEL;
  lp.ImageWanted:=PageNumber;

  GFLError:=gflLoadBitmap(PChar(FileName), gfl_bmp, lp, finfo);

  if GFLError=gfl_no_error then
  begin
    // Converting GFL bitmap to GDI+ one
    
    lngth:=gfl_bmp^.Height*gfl_bmp^.BytesPerLine;
    Result:=TGPBitmap.Create(gfl_bmp^.Width,gfl_bmp^.Height,PixelFormat32bppARGB);
    Result.LockBits(MakeRect(0,0,gfl_bmp^.Width,gfl_bmp^.Height),ImageLockModeWrite,PixelFormat32bppARGB,gpBitmapData);
    CopyMemory(gpBitmapData.Scan0,gfl_bmp^.Data,lngth);
    Result.UnlockBits(gpBitmapData);
  end
  else Result:=nil;
  gflFreeFileInformation(finfo);
  {gdip_bmp.Free;}
  gflFreeBitmap(gfl_bmp);
end;
This is doesn't eat memory, and it has never produced Access Violations yet. Still there's a problem with some PSD's (I don't need their layers, but even the thumbnail of particular PSD's won't load, it's a 100% transparent rectangle)

Posted: Sun Oct 09, 2005 7:52 pm
by RIMMER
Yep, thanks!

Posted: Mon Oct 10, 2005 6:56 am
by Guest
Hey, the reasons are most probably that GDI+ won't copy a picture memory. It seems to refuse copying even if we make a TGPBitmap.Clone. Even when we build a GDI+ bitmap from a stride0, it won't copy the memory. And the conversion function should always free the GFL bitmap. The memory, where now the GDI+ bitmap is based, gets free, thus, when we try to use a GDI+ bitmap in graphics, it produces Access Violation (AV). That's why my method makes just an empty GDI+ bitmap of the same size and then copies the momory from GFL bitmap to GDI+ one. The pixel format is chosen to 32 bpp ARGB because of maximum compatibility to any screen graphics. Good luck!