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

Working with jpg files

Unread post by Steve Lympany »

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: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

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

Unread post by Steve Lympany »

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: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

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: 204
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc »

: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: 56
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany »

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: 56
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany »

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 626 times
Paul Cerkez
VIP Member
Posts: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

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: 56
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany »

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: 106
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez »

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: 56
Joined: 31 Mar 2001 23:01

Unread post by Steve Lympany »

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
User avatar
drspro2
VIP Member
Posts: 97
Joined: 28 Apr 2006 12:03

GDI load and save to jpg bmp

Unread post by drspro2 »

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
User avatar
drspro2
VIP Member
Posts: 97
Joined: 28 Apr 2006 12:03

Unread post by drspro2 »

I think i might have found it,


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