Page 1 of 1
Pictures in an Internal Database
Posted: 9 Oct 2013 13:28
by Alfred
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
Posted: 9 Oct 2013 13:50
by Thomas Linder Puls
What do you mean by "picture"?
Re:
Posted: 9 Oct 2013 15:41
by Alfred
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.
Posted: 9 Oct 2013 20:38
by Thomas Linder Puls
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)
Re:
Posted: 10 Oct 2013 13:47
by Alfred
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
Posted: 11 Oct 2013 7:02
by Tonton Luc
Hi,
as you can see in the help file :
Code: Select all
binary::compress/1->
compress : (binary Input)
-> binary Output
language c.