Creating a simple graph

Discussions related to Visual Prolog
User avatar
Jan de Lint
VIP Member
Posts: 77
Joined: 6 Mar 2000 0:01

Creating a simple graph

Unread post by Jan de Lint » 9 Sep 2009 15:52

Dear all,
how does one create a simple graph in BMP or PNG format?
GDI+?
Can a metafile.emf simply be converted?
I need to output some performance characteristics graphically.
Thanks,
]an

Kari Rastas
Active Member
Posts: 31
Joined: 4 Mar 2000 0:01

Unread post by Kari Rastas » 10 Sep 2009 7:44

Well basically creating a graph is easy. You create a picture (vpi::pictOpen), make the wanted draw operations (axis, axis numbers, header, observations etc) and finally save the picture using vip::pictSave. The picture is saved in BMP format.

Saving the picture directly in PNG (or JPEG etc) format could be done like this

Code: Select all

    savePictureToFile(Picture,FileName) :-         vpi::pictSave(Picture,"x.bmp"),         gdiplus_api::startup(),         Image = gdiPlus::loadImageFromFile("x.bmp"),         TYPE = imageType(fileName::getExtension(FileName)),         CLSID = gdiPlus_api::gdipTryGetImageEncoder(TYPE),         gdiplus_api::checkStatus(gdiPlus_native::gdipSaveImageToFile(Image,FileName,CLSID,null),"gdipSaveImageToFile"),        gdiPlus_api::gdipDisposeImage(Image),        gdiplus_api::shutdown(),         !.
GDI+ is a real jungle and if your needs are simply to draw a simple chart I would recommend you forget GDI+. During the past years I have occasionally worked with the GDI+ "problem". I have had no big difficulties in producing rather complex GDI+ charts or drawings on the screen, but when it comes to saving the GDI+ picture I have not managed to find out how it is done. I have tried to figure out it several times and then got frustrated in the lack of success and have "forgotten" GDI+ for the next 6 months. :oops:

User avatar
Jan de Lint
VIP Member
Posts: 77
Joined: 6 Mar 2000 0:01

Unread post by Jan de Lint » 10 Sep 2009 9:28

Thanks Kari,
I'll try to explore the possibilities along the lines you suggest.
The VIP picturedraw example provides the opposite from what I need. The example assumes BMP and JPG files on disk and displays them on the screen.
OpenGL and the likes seem to be a bit heavy for my purpose, to use an understatement.
]an

Paul Cerkez
VIP Member
Posts: 94
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 10 Sep 2009 23:23

Jan,
the vpi picture predicates are relatively easy to use from scratch.

here is a short example code that I have used to create a terabytes worth of sample images for my NN research.

Code: Select all

    class facts - text_to_encode     picWin : pictureCanvas := erroneous.     controlRCT : rct := rct(0,0,256,256).   ...     clauses drawGraphicMorse(INint):-   ...         controlRCT = rct(_X1,_Y1,X2,Y2),         picWin := pictureCanvas::new(256,256),   % commented out due to te 9,944 'limit' %        picWin : setFont(vpi::fontCreateByName("Courier New",titleFontSize)),   % sets black on white         Fore = color_black,         Back = color_white,   % sets the inverse white on black %        Fore = color_white, %        Back = color_black,   % sets random colors for front and back %        randomColor(Fore, Back),   % Sets greys for front and back %        randomGrey(Fore, Back),           picWin : setForeColor(Fore),         picWin : setbackColor(Back),         picWin : setBrush(brush(pat_Solid, Back)),         picWin : drawFloodFill(pnt(1,1), Back),   ...           XT =convert(integer, math::random(220)),         YT = convert(integer, math::random(220)),   % draw the text ....        picWin : drawTextInRect(rct(XT,YT,X2,Y2),MOrse, [dtext_Left ,dtext_Wordbreak]),   % save the image         PIC = picWin : getPicture(),         wordname(RAW, NAME),         FileName = string::concat("MORSE ",/* RAW*/NAME, "-", IN, ".BMP"),         vpi::pictSave(PIC, FileName),           fail.   drawGraphicMorse(_INint).


P.
AI Rules!
P.

User avatar
Jan de Lint
VIP Member
Posts: 77
Joined: 6 Mar 2000 0:01

Unread post by Jan de Lint » 11 Sep 2009 7:58

Hi Paul,
this was not fun, but it is improving :-)
Thanks,
]an

User avatar
Jan de Lint
VIP Member
Posts: 77
Joined: 6 Mar 2000 0:01

Unread post by Jan de Lint » 11 Sep 2009 10:32

I just learned about the QGoogleVisualizationAPI
Perhaps even more fun!
If succesful I'll extend the examples in the VPcURL package.
]an

User avatar
Ferenc Nagy
VIP Member
Posts: 216
Joined: 24 Apr 2007 12:26

imageType

Unread post by Ferenc Nagy » 24 Mar 2015 18:16

Hi,
I suspect that this line is wrong in Kari's solution

Code: Select all

TYPE = imageType(fileName::getExtension(FileName)),
TIA, Regards,
Frank Nagy

Post Reply