Working with jpg files

Discussions related to Visual Prolog
Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Working with jpg files

Unread post by Steve Lympany » 27 Jun 2011 9:33

Hi,
Is there a better way of doing the following, eg using iStream_native, rather than working on disk?

Code: Select all

predicates     jpeg_picture:(string JpegFile)->picture. clauses     jpeg_picture(JPG)=Picture:-                 Workfile="C:\\a.bmp",         Bitmap=bitmap::createFromFile(JPG),             gdiplus::imageCodecInfo(JpegId, _, _, _, _, _, _, _, _, _, _, _, _) = getEncoder("BMP", gdiplus::imageEncoders),         Bitmap:saveToFile(WorkFile, JpegId, uncheckedConvert(gdiplus::encoderParameters, 0)),         Picture=vpi::pictLoad(WorkFile).
cheers
steve

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

Unread post by Tonton Luc » 27 Jun 2011 14:02


Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 27 Jun 2011 18:42

Hi Tonton,
Thanks, yes, I saw those, but they don't really help. I want to work with a vpi::picture, but load a jpg.

cheers
steve

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 29 Jun 2011 13:17

Steve,
when I looked into this a couple of years ago, what I found was to do the 'sonversion' between JPG to vip::Picture (which is BMP format), you will either need to write your own JPG file reader or lionk in a 3rd party tool.

P.
AI Rules!
P.

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

Unread post by Tonton Luc » 29 Jun 2011 15:35

:idea:
Maybee you can used an invisible imageControl like :

Code: Select all

        imageControl_ctl:setImageFile("your_picture.jpg"),         Img = imageControl_ctl:getImage(),
...and you recover a vpi::picture.

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 29 Jun 2011 18:05

Hi,
Many thanks for your thoughts.
Tonton, I assume you mean grab the picture from a window/form/screen....? It's an idea, but I think I (end-users) will lose resolution.

cheers
Steve

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 11 Jul 2011 14:31

Hello again,
Still fiddling around with this. The following code is supposed to convert a jpg to a bitmap. The reason I do it this way is that if I do it without any sizing, a 6Mb JPG converts to a 200Mb BMP. Unfortunately, the code below only produces a black bitmap.

Any ideas?

Code: Select all

predicates         jpgToBmp :(string JpgFile). clauses         jpgToBmp(JpgFile):-                 Image=image::createFromFile(JpgFile),                 Graphics=graphics::createFromImage(Image),                 Bitmap=bitmap::createFromGraphics(2000,2000,Graphics), %resize                 gdiplus::imageCodecInfo(BMPId, _, _, _, _, _, _, _, _, _, _, _, _) = getEncoder("BMP", gdiplus::imageEncoders),                 BitMapFile=fileName::setExtension(JpgFile,"bmp"),                 Bitmap:saveToFile(BitMapFile, BMPId, uncheckedConvert(gdiplus::encoderParameters, 0)),                 stdio::write("\nfile ",BitMapFile," saved \n").
Thanks
regards
steve
Attachments
gditestimage.zip
Convert jpeg to bitmap - fails!
(22.88 KiB) Downloaded 381 times

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 11 Jul 2011 22:48

Steve,
when I was 1st experimenting with GDI+ and JPGs, I could never get anything but a black screen. (was in VIP6.3)

Can you get the JPG to display properly?

P.
AI Rules!
P.

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 12 Jul 2011 7:25

Hi Paul,
I haven't tried. I want to open a jpg and use vpi::picture (which only reads a bmp). The following works:

Code: Select all

predicates    jpgToBmp :(string JpgFile). clauses    jpgToBmp(JpgFile):-       Image=image::createFromFile(JpgFile),%or bitmap::       gdiplus::imageCodecInfo(BMPId, _, _, _, _, _, _, _, _, _, _, _, _) = getEncoder("BMP", gdiplus::imageEncoders),       Image:saveToFile(BitMapFile, BMPId, uncheckedConvert(gdiplus::encoderParameters, 0)).
but this can create huge bmp files of course.

cheers
steve

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 12 Jul 2011 21:43

Steve,
you might want to look at some JPG compression or scaling algorithms and applying them before you do the conversion to reduce the BMP file size.

P.
AI Rules!
P.

Steve Lympany
VIP Member
Posts: 119
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany » 13 Jul 2011 8:49

Hi Paul,
Yes, I've tried that, and didn't get very far (after several hours). Hence the above idea,just to change the size.

Many thanks for the ideas. I'll continue to play and will post a solution if I am successful.

cheers
steve

drspro2
VIP Member
Posts: 78
Joined: 28 Apr 2006 12:03

GDI load and save to jpg bmp

Unread post by drspro2 » 27 Jan 2016 15:49

In VIP 75 in the GDI plus example i can get the example working, (saving as bmp or jpg to file
with the GDI predicates)

though in another project the GDI is included but gives an error

when trying to find the the codecs info, through these predicates

it gives acces violation, i cant find what the couase is or what the difference is between the two projects


any idea is very much appreciated,

thankyou

drspro2
VIP Member
Posts: 78
Joined: 28 Apr 2006 12:03

Unread post by drspro2 » 27 Jan 2016 16:51

I think i might have found it,


i didnt use Vargdi = gdiplus::startUp(),

Post Reply