Encoding data to a PNG file

260 views
Skip to first unread message

Samuel Iglesias Gonsálvez

unread,
Jan 16, 2014, 3:53:12 AM1/16/14
to skia-d...@googlegroups.com
Hello,

I have a problem when trying to encode a bitmap into a PNG file using Skia. The example code draws three rectangles to a bitmap and tries to save it into a PNG image.

I have tested with Cairo in order to check that the bitmap is actually being painted, however SkImageEncoder::EncodeFile gave an error. Using GDB I found that the created SkImageEncoder is a NULL pointer, so EncodeFile fails.

Attached to this email there are three files: the example I want to run (main.cpp), the GYP file to generate it (main.gyp) and the resulting image from Cairo.

I have tested the SampleApp's slide test (samplecode/SampleSlides.cpp) which worked like a charm, so I guess that the error I have is about missing initialization or wrong compilation flags.

Anything I missed here?

Sam
main.cpp
main.gyp
snapshot-cairo.png

Leon Scroggins

unread,
Jan 16, 2014, 9:50:13 AM1/16/14
to skia-d...@googlegroups.com
The linker strips code that is not used directly, and since you never directly used the class SkPNGImageDecoder, it does not get included in the final executable. So EncodeFile fails to find it.

Try adding the following to main.cpp:

#include "SkForceLinking.h"
__SK_FORCE_IMAGE_DECODER_LINKING;

This will ensure that it gets linked properly.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/groups/opt_out.



--
Leon Scroggins III
scr...@google.com

Samuel Iglesias Gonsálvez

unread,
Jan 20, 2014, 2:33:12 AM1/20/14
to skia-d...@googlegroups.com

Hello Leon,


El jueves, 16 de enero de 2014 15:50:13 UTC+1, scroggo escribió:
The linker strips code that is not used directly, and since you never directly used the class SkPNGImageDecoder, it does not get included in the final executable. So EncodeFile fails to find it.

Try adding the following to main.cpp:

#include "SkForceLinking.h"
__SK_FORCE_IMAGE_DECODER_LINKING;

This will ensure that it gets linked properly.

Thanks a lot, it works like a charm!

Best regards,

Sam

 
Reply all
Reply to author
Forward
0 new messages