GFL -> GDI+
-
- Posts: 2
- Joined: Sun Oct 09, 2005 9:52 am
GFL -> GDI+
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?
-
- Author of XnView
- Posts: 45233
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: GFL -> GDI+
You can use ConvertBitmapToDIB or HBmp, i'm sure that in your TGPBitmap you have a method to use a HBITMAPRIMMER 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?
Pierre.
Re: GFL -> GDI+
For some reasons it didn't work fine for me. This is what i do now:xnview wrote:You can use ConvertBitmapToDIB or HBmp, i'm sure that in your TGPBitmap you have a method to use a HBITMAP
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;
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!