Loading a bmp and jpg to a dialog

Discussions related to Visual Prolog
rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 8 Jul 2020 16:42

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).
FR

User avatar
Gukalov
Active Member
Posts: 25
Joined: 5 Oct 2011 15:16

Re: Loading a bmp and jpg to a dialog

Unread post by Gukalov » 9 Jul 2020 12:41

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.

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 9 Jul 2020 22:55

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
FR

Harrison Pratt
VIP Member
Posts: 323
Joined: 5 Nov 2000 0:01

Re: Loading a bmp and jpg to a dialog

Unread post by Harrison Pratt » 10 Jul 2020 17:22

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.

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 10 Jul 2020 18:27

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
FR

User avatar
Gukalov
Active Member
Posts: 25
Joined: 5 Oct 2011 15:16

Re: Loading a bmp and jpg to a dialog

Unread post by Gukalov » 10 Jul 2020 18:53

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:

Harrison Pratt
VIP Member
Posts: 323
Joined: 5 Nov 2000 0:01

Re: Loading a bmp and jpg to a dialog

Unread post by Harrison Pratt » 10 Jul 2020 19:37

It works the same way in VIP 9x.

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 10 Jul 2020 20:18

Fantasssssssssssstic. Thank you Gukalov.
FR

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 10 Jul 2020 20:25

Thanks Harrison.
FR

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 11 Jul 2020 20:19

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
FR

User avatar
Gukalov
Active Member
Posts: 25
Joined: 5 Oct 2011 15:16

Re: Loading a bmp and jpg to a dialog

Unread post by Gukalov » 12 Jul 2020 20:42

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

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

Re: Loading a bmp and jpg to a dialog

Unread post by Thomas Linder Puls » 12 Jul 2020 22:43

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).
Regards Thomas Linder Puls
PDC

rasvprolog
Active Member
Posts: 29
Joined: 1 May 2014 3:28

Re: Loading a bmp and jpg to a dialog

Unread post by rasvprolog » 13 Jul 2020 15:31

Wonderful!
FR

Post Reply