Pictures in an Internal Database

Discussions related to Visual Prolog
Alfred
Posts: 5
Joined: 9 Oct 2013 13:11

Pictures in an Internal Database

Unread post by Alfred » 9 Oct 2013 13:28

Hi,

I would like to include pictures into an internal database like (Name, FirstName, Picture etc.). How can I insert pictures into such a database :?:

Thanks for your reply :D

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 9 Oct 2013 13:50

What do you mean by "picture"?
Regards Thomas Linder Puls
PDC

Alfred
Posts: 5
Joined: 9 Oct 2013 13:11

Re:

Unread post by Alfred » 9 Oct 2013 15:41

That means a visual representation of a person. See as follows:

class facts - db_pic
db_pic : (string Name,string FirstName, picture Picture).

predicates
onPaint : drawWindow::paintResponder.

clauses
onPaint(_Source, Rectangle, GDI):-
retractAll(db_pic(_,_,_)),
FileName="Hydrangeas1.bmp",
Pic=vpi::pictLoad(fileName(FileName),100,100,0x0020),
file::delete("db_pic.bmp"),
assert(db_pic("Meier","Tom",Pic)),
file::save("db_pic.bmp",db_pic),
GDI:pictDraw(Pic, pnt(250,10), rop_SrcCopy),
W= pictOpen(Rectangle),
Pic= pictClose(W),
retractAll(db_pic(_,_,_)),!.

onPaint(_Source, _Rectangle, _GDI).

Picture appears into the dialog; but it seems to be, that the picture is not included into the database as mentioned. When database is reloaded, there is no picture at all.

User avatar
Thomas Linder Puls
VIP Member
Posts: 1174
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 9 Oct 2013 20:38

OK, so the problem is saving and loading the vpiDomains::picture.

However a vpiDomains::picture is actually a pointer to "something":

Code: Select all

domains     picture = pointer.     % @short Handle to a picture.     % @end
If you save a pointer and load it again "another day" it will point to something different (or nothing at all).

You can however obtain a binary that represents the image, and that binary can be saved and loaded and reconverted into a picture (in the vpi class):

Code: Select all

predicates     pictToBin : (vpiDomains::picture Picture) -> binary Binary language c as runtimeLinknamesVpi::pict_ToBin.     % @short Converts the #Picture picture into the #Binary binary format.     % @detail Binary has exactly the same format as BMP file.     % @end   predicates     pictFromBin : (binary Binary) -> vpiDomains::picture Picture language c as runtimeLinknamesVpi::pict_FromBin.     % @short Retrieves the #Picture picture from the #Binary binary. <br>     % @detail Binary has exactly the same format as BMP file.     % @end
So if you let the database contain the binary-picture instead of the pointer-picture it can be saved and loaded.

(It will however use a lot of disk space)
Regards Thomas Linder Puls
PDC

Alfred
Posts: 5
Joined: 9 Oct 2013 13:11

Re:

Unread post by Alfred » 10 Oct 2013 13:47

Thomas Linder Puls wrote:OK, so the problem is saving and loading the vpiDomains::picture.

However a vpiDomains::picture is actually a pointer to "something":

Code: Select all

domains     picture = pointer.     % @short Handle to a picture.     % @end
If you save a pointer and load it again "another day" it will point to something different (or nothing at all).

You can however obtain a binary that represents the image, and that binary can be saved and loaded and reconverted into a picture (in the vpi class):

Code: Select all

predicates     pictToBin : (vpiDomains::picture Picture) -> binary Binary language c as runtimeLinknamesVpi::pict_ToBin.     % @short Converts the #Picture picture into the #Binary binary format.     % @detail Binary has exactly the same format as BMP file.     % @end   predicates     pictFromBin : (binary Binary) -> vpiDomains::picture Picture language c as runtimeLinknamesVpi::pict_FromBin.     % @short Retrieves the #Picture picture from the #Binary binary. <br>     % @detail Binary has exactly the same format as BMP file.     % @end
So if you let the database contain the binary-picture instead of the pointer-picture it can be saved and loaded.

(It will however use a lot of disk space)
Thanks Thomas, any other way using pictures at the least possible disk space.

Regards

User avatar
Tonton Luc
VIP Member
Posts: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 11 Oct 2013 7:02

Hi,

:idea: as you can see in the help file :

Code: Select all

binary::compress/1-> compress : (binary Input)     -> binary Output     language c.

Post Reply