Convert image from Fl_JPEG_Image to Fl_PNG_Image

190 views
Skip to first unread message

Haavard Holm

unread,
May 19, 2018, 3:42:45 PM5/19/18
to fltk.general

Hello,

I have a picture-file stored on disk in jpeg-format.

I want to read it, but to store it in a FL_PNG_IMAGE.
Is it possible to read it using something like
   my_jpeg = new Fl_JPEG_Image("mypic.jpeg");
and then convert it to an FL_PNG_IMAGE ?

Best regards
Håvard

Greg Ercolano

unread,
May 19, 2018, 4:50:10 PM5/19/18
to fltkg...@googlegroups.com
FLTK doesnt include any image write routines that I know of,
but it does include the png and jpeg libraries, so you should
be able to use e.g. the png library's image write functions to
write the rgb pixels out of the FLTK image buffer, and write them
back to disk.

I /think/ the png library's functions, when linked into an
FLTK program, will be visible to the main application.

See the fltk/png/libpng-manual.txt for info on how to use
the PNG library functions, or the online docs at
http://www.libpng.org/

Perhaps someone has posted code doing this from within
FLTK before -- I can't recall. But likely you'll need the
Fl_Image methods data_w(), data_h(), d() and data()
for the image width, height, depth, and raw data (respectively)
to access the raw pixel data, and then pass that down to the
png library to open/write/close the png file.

Typically people use an image conversion tool like imagemagick
to convert one image file format to another.

Haavard Holm

unread,
May 20, 2018, 5:27:35 AM5/20/18
to fltk.general
Hi,

Thanks for your answer, but I guess I was not clear when asking.

I am not interested in writing the file to disk. I simply want to use an FL_PNG_IMAGE to keep my jpeg-image.
Is that possible ?

Best regards
Håvard

Albrecht Schlosser

unread,
May 20, 2018, 8:09:05 AM5/20/18
to fltkg...@googlegroups.com
On 20.05.2018 11:27 Haavard Holm wrote:

> I am not interested in writing the file to disk. I simply want to use an
> FL_PNG_IMAGE to keep my jpeg-image.
> Is that possible ?

Why do you want to do that? This doesn't sound useful. Can you explain
what you want to achieve so we can help you better?

That said, the common base class of Fl_PNG_Image and Fl_JPEG_Image is
Fl_RGB_Image. IMHO it would be more useful to cast your pointers (down)
to Fl_RGB_Image* if you want to use a common class (unless you modify
anything *inside* the images).

Haavard Holm

unread,
May 21, 2018, 2:41:47 AM5/21/18
to fltk.general
Hi,

What I want to achieve :
I have some images in rgb-format and want to merge these with some images in jpeg-format.

I did as you suggested and that seems to work fine. Now I store all in the FL_RGB_Image class.

Thanks
Håvard

Daniel Polski

unread,
May 21, 2018, 1:19:54 PM5/21/18
to fltkg...@googlegroups.com
Hello,
Before I reinvent the wheel.. Anyone got any free to use
date/datetime/time pickers? (I'm using fltk 1.3.4)

/Daniel

Nikita

unread,
May 21, 2018, 5:02:08 PM5/21/18
to fltkg...@googlegroups.com, dan...@agelektronik.se
Well, I've got a class Fl_Calendar (date picker) that was written for my
goals some time ago. It uses only system functions, so output depends on
locale (don't be afraid of screenshot with cyrillic :).
But I used the class on Windows (FLTK 1.3.4) only. I hope it will need
only small changes to work on *nix.
The class is in attached files. An example of usage is in .cxx file
inside '#ifdef TEST'.

Feel free to use and improve.

Nikita
calendar.png
Fl_Calendar.cxx
Fl_Calendar.h

Daniel Polski

unread,
May 22, 2018, 6:44:28 AM5/22/18
to fltkg...@googlegroups.com
Perfect, thanks!

/Daniel

Karl Harbinger

unread,
Aug 16, 2018, 11:25:52 AM8/16/18
to fltk.general
You can also use FDate and Fl_Calendar classes from flek: https://sourceforge.net/projects/flek/files/flek/0.2/

Here are slightly modified versions of those two classes: https://github.com/darealshinji/fltk-dialog

Jean-Yves Garneau

unread,
Jul 13, 2019, 10:09:40 AM7/13/19
to fltk.general
Thank you Nikita. The look is want I search for. It seem working for the first row only. Others rows don't send event.

Jean-Yves Garneau

unread,
Jul 13, 2019, 10:41:36 AM7/13/19
to fltk.general
Problem fixed! The parent must be large enough.
Reply all
Reply to author
Forward
0 new messages