Page 1 of 1

Loading a bmp and jpg to a dialog

Posted: 8 Jul 2020 16:42
by rasvprolog
Hello,
I am using an OK button to go from one dialog A to dialog B. Dialog B uses the following commands to load a .bmp and .jpg files to the screen. Most of the times there is no problem, but every now and then dialog B fails to load the .bmp file (it always happen to .bmp not .jpg). The file sizes are about 24K and the bmp is (256 color bmp). Anyone any idea why this might happen. Thank you in advance.
Frank

Code: Select all

clauses     new(Parent) :-         dialog::new(Parent),         pict := vpi::pictLoad("welldefsch.bmp"),              _ = gdiplus_native::gdipLoadImageFromFile("welldefimg.jpg", Image),         pictPlus := Image,        addMenuItemListener(onMenu),         setpaintresponder(onPaint),         generatedInitialize().     predicates     onPaint : drawwindow::paintresponder. clauses     onPaint(_, _, Gdiobject):-         Gdiobject:pictDraw(pict, pnt(140,5), vpiDomains::rop_SrcCopy),               HDC = Gdiobject:getNativeGraphicContext(IsReleaseNeeded),         _ = gdiplus_native::gdipCreateFromHDC(HDC, Graphics),        _ = gdiplus_native::gdipDrawImageI(Graphics, pictPlus, 685, 10),         _ = gdiplus_native::gdipDeleteGraphics(Graphics),         Gdiobject:releaseNativeGraphicContext(HDC, IsReleaseNeeded).

Re: Loading a bmp and jpg to a dialog

Posted: 9 Jul 2020 12:41
by Gukalov
Hi.
Just to draw a picture from a file?
Using ImageControl is the simplest way, I guess.

Code: Select all

    setImageFile : (string FileName).     % @short Loads the control image from the specified file.

Re: Loading a bmp and jpg to a dialog

Posted: 9 Jul 2020 22:55
by rasvprolog
Thank you. I tried to use what you suggested : setImageFile : (string FileName). but unfortunately I get an error "undeclared identifier". Probably I am not using the full nomenclature.

Thanks

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 17:22
by Harrison Pratt
I think you need to add the imageControl package to your project. In my system it is here:

"C:\Program Files (x86)\Visual Prolog 9\pfc\gui\controls\imageControl\imageControl.pack"

It does not show up in the project browser until you add it, unlike most of the packages in the PFC.

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 18:27
by rasvprolog
Thanks Harrison,
I added the imageControl pack and it shows up under the project pfc directory. But somehow the program does not recognize "setImageFile (FileName)". Instead of that I am using pict := vpi::pictLoad("yyy.bmp"), which works fine but every now and then it becomes unstable and does not load the file, but on the second try it continues to work fine. Strange!
Best,
Frank

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 18:53
by Gukalov
Open dialog constructor.
In window "Controls" click key symbol.
Click in the dialog area.
In appeared list choose "imageControl".
O'k button.
"imageControl_ctl" will appear - rename as you want, replace as you want, resize as you want.........
(all needed packages added automatically)
Add "onShow" event of dialog " imageControl_ctl.setImageFile(FileName)".
Be happy)))


I have some old version of VIP - may be today it can be done simplier :roll:

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 19:37
by Harrison Pratt
It works the same way in VIP 9x.

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 20:18
by rasvprolog
Fantasssssssssssstic. Thank you Gukalov.

Re: Loading a bmp and jpg to a dialog

Posted: 10 Jul 2020 20:25
by rasvprolog
Thanks Harrison.

Re: Loading a bmp and jpg to a dialog

Posted: 11 Jul 2020 20:19
by rasvprolog
Thanks again to wonderful contributing experts of the forum.
I just wanted to add a feedback on the outcome of loading the files by the two different methods. using setImageFile : (string FileName) as suggested by Gukalov was easier and more straightforward than using complicated pict := vpi::pictLoad("FileName"). It resolved the instability problem that I indicated earlier. However it seems when the same file (occupying the same rectangular size on the dialog) when it was loaded by vpi::picLoad(FileName) appears sharper than the other method. The difference is more apparent when the image contains some text. I tried several times to make sure it was not just imagination.

Best,
Frank

Re: Loading a bmp and jpg to a dialog

Posted: 12 Jul 2020 20:42
by Gukalov
Don't forget:

Code: Select all

class bitmap : bitmap

Code: Select all

class image : image
You can create a bitmap (image) from a file and from any other... From everything you need to create)))
And edit it as you want to edit...

Good luck)))

P.S. imageControl, by the way, works perferctly with VPI picture (without all "onPaint"):

Code: Select all

interface imageControl ... ... predicates         setImage : (vpiDomains::picture Image).          % @short Sets the specified VPI picture.          % @end

Re: Loading a bmp and jpg to a dialog

Posted: 12 Jul 2020 22:43
by Thomas Linder Puls
Notice that the gdi+ stuff also have an object interface (in $(ProDir)\pfc\gui\gdiplus).

Also notice that gdi+ can load images from many file formats.

So all in all the code can also be made like this:

Code: Select all

facts     welldefsch_bmp : image := image::createFromFile(@"welldefsch.bmp").     welldefsch_jpg : image := image::createFromFile(@"welldefsch.jpg").   predicates     onPaint : window::paintresponder. clauses     onPaint(_, _, GDI) :-         HDC = GDI:getNativeGraphicContext(IsReleaseNeeded),         Graphics = graphics::createFromHDC(HDC),         Graphics:drawImageI(welldefsch_bmp, 140, 5),         Graphics:drawImageI(welldefsch_jpg, 685, 10),         Graphics:delete(),         GDI:releaseNativeGraphicContext(HDC, IsReleaseNeeded).

Re: Loading a bmp and jpg to a dialog

Posted: 13 Jul 2020 15:31
by rasvprolog
Wonderful!