Page 1 of 1

Working with jpg files

Posted: 27 Jun 2011 9:33
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

Posted: 27 Jun 2011 14:02
by Tonton Luc

Posted: 27 Jun 2011 18:42
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

Posted: 29 Jun 2011 13:17
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.

Posted: 29 Jun 2011 15:35
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.

Posted: 29 Jun 2011 18:05
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

Posted: 11 Jul 2011 14:31
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

Posted: 11 Jul 2011 22:48
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.

Posted: 12 Jul 2011 7:25
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

Posted: 12 Jul 2011 21:43
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.

Posted: 13 Jul 2011 8:49
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

GDI load and save to jpg bmp

Posted: 27 Jan 2016 15:49
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

Posted: 27 Jan 2016 16:51
by drspro2
I think i might have found it,


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