gflLoadBitmapFromHandle with Delphi

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

Moderators: XnTriq, xnview

Philips10
Posts: 7
Joined: Wed Feb 09, 2005 9:36 am

gflLoadBitmapFromHandle with Delphi

Post by Philips10 »

Hi Pierre

Could you please give us Delphi-programmers a few lines of code that shows us how to use gflLoadBitmapFromHandle

I got

Code: Select all

ms := tmmorystream.creat 
try 
........ 
image1.picture.bitmap.savetostream(ms); 
e := gflLoadBitmapFromHandle( ?? , gfl_bmp, lp, fInfo); 
......... 
finally 
ms.free; 
end; 
If this is right so far, what to add for the two questionmarks ??

If not at all, please a few lines that shows the use of gflLoadBitmapFromHandle

Thanks and kind Regards

Jansen
User avatar
xnview
Author of XnView
Posts: 36805
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: gflLoadBitmapFromHandle with Delphi

Post by xnview »

Philips10 wrote:Could you please give us Delphi-programmers a few lines of code that shows us how to use gflLoadBitmapFromHandle

I got

Code: Select all

ms := tmmorystream.creat 
try 
........ 
image1.picture.bitmap.savetostream(ms); 
e := gflLoadBitmapFromHandle( ?? , gfl_bmp, lp, fInfo); 
......... 
finally 
ms.free; 
end; 
If this is right so far, what to add for the two questionmarks ??

If not at all, please a few lines that shows the use of gflLoadBitmapFromHandle
I don't know very well Delphi, perhaps someone who knows Delphi & C/C++ can help...
Pierre.
Andreas

Re: gflLoadBitmapFromHandle with Delphi

Post by Andreas »

Here is a small example in Borland C++.
A conversion to Delphi should be easy.

Code: Select all

//*********************
//       CALLBACKS       
//*********************
//---------------------------------------------------------------------------
GFL_UINT32 GFLAPI myReadFunction(GFL_HANDLE handle, void *buffer,
                                 GFL_UINT32 size)
{
    int ret = 0;
    TStream *s = (TStream *)handle;

    ret = s->Read(buffer, size);

    return ret;
}
//---------------------------------------------------------------------------
GFL_UINT32 GFLAPI myTellFunction(GFL_HANDLE handle)
{
    TStream *s = (TStream *)handle;
    return s->Position;
}
//---------------------------------------------------------------------------
GFL_UINT32 GFLAPI mySeekFunction(GFL_HANDLE handle, GFL_INT32 offset,
                                 GFL_INT32 origin)
{
    Word soOrigin = 0;
    TStream *s = (TStream *)handle;

    switch(origin)
    {
        case SEEK_END:
            soOrigin = soFromEnd;
            break;

        case SEEK_CUR:
            soOrigin = soFromCurrent;
            break;

        case SEEK_SET:
        default:
            soOrigin = soFromBeginning;
            break;
    }

    s->Seek(offset, soOrigin);

    return s->Position;
}
//---------------------------------------------------------------------------

//*******************
//        TestFunc        
//*******************
void __fastcall TForm1::Testfunc()
{
    
    GFL_LOAD_PARAMS lp;
    GFL_FILE_INFORMATION fi;
    GFL_BITMAP *gflbmp;
    GFL_ERROR error;

    TMemoryStream *ms = new TMemoryStream();
    

    ........


    Image1->Picture->Bitmap->SaveToStream(ms);

    gflGetDefaultLoadParams(&lp);
    lp.ColorModel = GFL_BGR;
    lp.LinePadding = 4;
    lp.Callbacks.Read = myReadFunction;
    lp.Callbacks.Tell = myTellFunction;
    lp.Callbacks.Seek = mySeekFunction;


    error = gflLoadBitmapFromHandle((GFL_HANDLE)ms, &gflbmp, &lp, &fi);


    ........


    gflFreeBitmap(gflbmp);
    delete ms;
}
Andreas