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

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

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

Unread post by Chan Bok » 18 May 2006 8:47

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: 9
Joined: 3 May 2000 23:01

Unread post by Yuri Ilyin » 18 May 2006 9:48

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
VIP Member
Posts: 69
Joined: 13 Sep 2000 23:01

Unread post by Chan Bok » 18 May 2006 10:28

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: 9
Joined: 3 May 2000 23:01

Unread post by Yuri Ilyin » 18 May 2006 11:08

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: 388
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 18 May 2006 12:27

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
VIP Member
Posts: 69
Joined: 13 Sep 2000 23:01

Unread post by Chan Bok » 18 May 2006 15:00

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: 388
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 18 May 2006 15:45

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