Share Tips, Code Samples, etc. with the Visual Prolog community.
Chan Bok
Active Member
Posts: 26
Joined: 13 Sep 2000 23:01

(Howto) Convert a vpi Picture to a GDI+ Image

Unread post by Chan Bok »

After some searching on the web, I manage to convert
a vpi Picture to a gdi+ Image:

Code: Select all

gpPictToImage(Pict,Image):-     PictBin = vpi::pictToBin(Pict),     MemSize = binary::getSize(PictBin),     HGlobal = util::globalAlloc(0x0042,MemSize),            % GMEM_MOVEABLE + GMEM_ZEROINIT = 0x0002 + 0x0040     Pointer = util::globalLock(HGlobal),     PointerBin = uncheckedConvert(pointer,PictBin),     memory::copy(Pointer,PointerBin,MemSize),               _ = createStreamOnHGlobal(HGlobal,b_true,Stream),  % b_true = DeleteOnRelease     _ = gdip::gdipLoadImageFromStream(Stream,Image).
The above globalAlloc and globalLock are the usual C equivalent
of the same name.

I have yet to find a way to convert the other way round, i.e. from
Image to Picture (other than saving the Image as a file and reading
the file using vpi).

Chan Bok
Axon Research
Yuri Ilyin
Posts: 5
Joined: 3 May 2000 23:01

Unread post by Yuri Ilyin »

Hi Chan.

Please notice that VPI Picture is a DIB image in BMP format. So if you save GDI+ as BMP, then it should help.
regards Yuri.
Chan Bok
Active Member
Posts: 26
Joined: 13 Sep 2000 23:01

Unread post by Chan Bok »

Dear Yuri,

I believe there is a way to do it in memory without saving to file.
Perhaps someone has the solution.

Chan Bok
Axon Research
Yuri Ilyin
Posts: 5
Joined: 3 May 2000 23:01

Unread post by Yuri Ilyin »

Dear Chan.

Of course, it is possible to save on a stream, and then HGlobal can be created from such stream.
In my former message I mainly answered to you about format.
regards Yuri.
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

Is this what you need?

Code: Select all

gdiplus_native::gdipCreateBitmapFromGdiDib/3->   gdipCreateBitmapFromGdiDib : (     pointer GdiBitmapInfo,     pointer GdiBitmapData,     gdiplusBitmap Bitmap)     -> gpStatus     procedure (i,i,o)     language apicall. See details in MSDN.  
AI Rules!
P.
Chan Bok
Active Member
Posts: 26
Joined: 13 Sep 2000 23:01

Unread post by Chan Bok »

Dear Paul,

Thanks for your suggestion but this seems to be the reversed conversion.
I am looking for the Image -> Picture conversion.
Anyway I have already have a "quick and dirty" solution by writing to a temporary
disk file. Just wondering if there is a better way not using a disk file.

Chan Bok
Axon Research
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

going from Gdi+IMAGE to a gdi+BITMAP?

Code: Select all

gdiplus_native::gdipGetImageGraphicsContext/2-> gdipGetImageGraphicsContext : (     gdiplusImage Image,     gpGraphics Graphics)     -> gpStatus     procedure (i,o)     language apicall. See details in MSDN.
then

Code: Select all

gdiplus_native::gdipCreateBitmapFromGraphics/4-> gdipCreateBitmapFromGraphics : (     integer Width,     integer Height,     gpGraphics Target,     gdiplusBitmap Bitmap)     -> gpStatus     procedure (i,i,i,o)     language apicall. See details in MSDN.  
the part I haven't figured out yet is going from the gdi+BITMAP to a VIP Bitmap.
AI Rules!
P.
Post Reply