I have used these.
Code: Select all
predicates
savePictureToFile : (vpiDomains::picture, string FileName, string EncoderType) procedure (i,i,i) language stdcall as "savePictureToFile".
%
%@short Saves a picture in a file with the wanted picture format
%
%@detail Saves a picture in a file with the wanted picture format
%
%Possible formats are bmp, gif, jpeg, tiff and png
%
%@example
% PICTURE = O: getPicture(),
% picCore::savePictureToFile(PICTURE,"example1.jpg","jpeg"),
% picCore::savePictureToFile(PICTURE,"example2.bmp","bmp"),
% picCore::savePictureToFile(PICTURE,"example3.tif","tiff"),
% picCore::savePictureToFile(PICTURE,"example4.png","png"),
%
%@end
%
savePictureToFileJPEG : (vpiDomains::picture, string FileName) procedure (i,i) language stdcall as "savePictureToFileJPEG".
%
%@short Saves a picture in a file with jpeg format
%
%@detail Saves a picture in a file with jpeg format
%
%@example
% PICTURE = O: getPicture(),
% picCore::savePictureToFileJPEG(PICTURE,"example12.jpg"),
%
%@end
%
pictureFileToStringForHtml:(string PictureFileName,string PctureType,string NameText,unsigned Width,unsigned Height) -> string PicStr procedure (i,i,i,i,i) language stdcall as "pictureFileToStringForHtml".
%
%@short Produces from a picture file a string to be embedded in a html page
%
%@detail Produces from a picture file a string to be embedded in a html page.
%
%<img src=\"data:image/%;base64,%s\" alt=\"%s\" width=\"%\" height=\"%\">
%
%@example
% PICTURE = O: getPicture(),
% picCore::pictureFileToStringForHtml("example12.jpg","Export to USA in 2015",500, 250) = PictureStr,
%
%@end
%
pictureToStringForHtml:(vpiDomains::picture [in],string NameText [in],unsigned Width [in],unsigned Height [in]) -> string PicStr procedure (i,i,i,i) language stdcall as "pictureToStringForHtml".
%
%@short Produces from a picture a string to be embedded in a html page
%
%@detail Produces from a picture a string to be embedded in a html page.
%
%<img src=\"data:image/%;base64,%s\" alt=\"%s\" width=\"%\" height=\"%\">
%
%@example
% PICTURE = O: getPicture(),
% picCore::pictureToStringForHtml(PICTURE,"Export to USA in 2015",500, 250) = PictureStr,
%
%@end
%
clauses
savePictureToFile(PIC,FileName,OEnc):-
Enc = string::toUpperCase(OEnc),
Enc in ["JPEG","BMP","TIFF","GIF","PNG","WMF","EMF","ICON"],!,
GdiPlusToken = gdiplus::startup(),
gpPictToImage(PIC, Image),
ImageClone = Image:clone(),
Image : dispose(),
gdiplus :: imageCodecInfo(JpegId, _, _, _, _, _, _, _, _, _, _, _, _) = getEncoder(Enc, gdiplus::imageEncoders),
ImageClone : saveToFile(FileName, JpegId, uncheckedConvert(gdiplus::encoderParameters, null)),
ImageClone : dispose(),
gdiplus :: shutdown(GdiPlusToken),
memory::garbageCollect().
savePictureToFile(_,_,_).
clauses
savePictureToFileJPEG(PIC,FileName):-
GdiPlusToken = gdiplus::startup(),
gpPictToImage(PIC, Image),
gdiplus :: imageCodecInfo(JpegId, _, _, _, _, _, _, _, _, _, _, _, _) = getEncoder("JPEG", gdiplus::imageEncoders),
Image : saveToFile(FileName, JpegId, uncheckedConvert(gdiplus::encoderParameters, null)),
Image : dispose(),
gdiplus :: shutdown(GdiPlusToken),
_ = vpi::processEvents(),
memory::garbageCollect().
class predicates
getEncoder : (string FormatDescription, gdiplus::imageCodecInfo* EncoderList) -> gdiplus::imageCodecInfo Encoder.
clauses
getEncoder(FormatDescription, [Encoder|_]) = Encoder :-
gdiplus::imageCodecInfo(_, _, _, _, FormatDescription, _, _, _, _, _, _, _, _) = Encoder,
!.
getEncoder(FormatDescription, [_|Rest]) = getEncoder(FormatDescription, Rest).
getEncoder(FormatDescription, []) = _ :-
common_exception::raise_errorf(classInfo, predicate_name(), "Unsupported image format '%'", FormatDescription).
class predicates
gpPictToImage : ( vpiDomains::picture Pict [in], image Image [out]).
clauses
gpPictToImage(Pict, Image):-
PictBin = vpi::pictToBin(Pict),
MemSize = binary::getSize(PictBin),
HGlobal = memory_native::globalAlloc(memory_native::gmem_GHND, convert(unsigned, MemSize)),
% GHND = GMEM_MOVEABLE + GMEM_ZEROINIT = 0x0002 + 0x0040
Pointer = memory_native::globalLock(HGlobal),
PointerBin = uncheckedConvert(pointer, PictBin),
memory::copy(Pointer, PointerBin, MemSize),
_ = iStream_api::createStreamOnHGlobal(HGlobal, 1, Stream),
Image = image::createFromStream(Stream),
_ = memory_native::globalUnlock(HGlobal).
clauses
pictureFileToStringForHtml(PictureFile,Type,NameText,Width,Height) =PicStr:-
file::existFile(PictureFile),
BIN = cryptography::base64_encode(file::readBinary(PictureFile)),
PicStr = string::format("\n<img src=\"data:image/%;base64,%s\" alt=\"%s\" width=\"%\" height=\"%\">\n",
Type,
BIN,
NameText,
Width,
Height),!.
pictureFileToStringForHtml(_PictureFile,_Type,_NameText,_Width,_Height) ="".
clauses
pictureToStringForHtml(Pict,NameText,Width,Height) =PicStr:-
savePictureToFile(Pict,"workpic.jpg","jpeg"),
pictureFileToStringForHtml("workpic.jpg","jpeg",NameText,Width,Height) =PicStr.
Example of a picture created as Visual Prolog picture and saved in png format - size 26 kB.