Fragile at best:
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
in.close();
QFile out
("tawny_out.png");
s << ba;
out.close();
}
}
return app.exec();
}
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFile in("tawny.png");
if (in.open(QIODevice::ReadOnly)) {
QByteArray ba = in.readAll();
in.close();
QFile out("tawny_out.png");
if (out.open(QIODevice::WriteOnly)) {
QTextStream s(&out);
s << ba;
out.close();
}
}
return app.exec();
}
To copy to clipboard, switch view to plain text mode
With this image in:
tawny.jpg
(I cannot upload the output file: the forum thinks it isn't valid)
It has produced a broken header in the output:
chrisw@newton /tmp/simple_example $ file *.png
tawny_out.png: data
tawny.png: PNG image data, 612 x 816, 8-bit/color RGB, non-interlaced
chrisw@newton /tmp/simple_example $ identify tawny*.png
tawny.png PNG 612x816 612x816+0+0 8-bit DirectClass 750KBB 0.000u 0:00.010
identify: improper image header `tawny_out.png' @ error/png.c/ReadPNGImage/2842.
chrisw@newton /tmp/simple_example $ file *.png
tawny_out.png: data
tawny.png: PNG image data, 612 x 816, 8-bit/color RGB, non-interlaced
chrisw@newton /tmp/simple_example $ identify tawny*.png
tawny.png PNG 612x816 612x816+0+0 8-bit DirectClass 750KBB 0.000u 0:00.010
identify: improper image header `tawny_out.png' @ error/png.c/ReadPNGImage/2842.
To copy to clipboard, switch view to plain text mode
The file is broken at the very first byte of the 8-byte header by UTF-8 encoding of that byte:
chrisw@newton /tmp/simple_example $ od -tx1 -tc -N 8 tawny.png
0000000 89 50 4e 47 0d 0a 1a 0a
211 P N G \r \n 032 \n
0000010
chrisw@newton /tmp/simple_example $ od -tx1 -tc -N 8 tawny_out.png
0000000 c2 89 50 4e 47 0d 0a 1a
302 211 P N G \r \n 032
0000010
chrisw@newton /tmp/simple_example $ od -tx1 -tc -N 8 tawny.png
0000000 89 50 4e 47 0d 0a 1a 0a
211 P N G \r \n 032 \n
0000010
chrisw@newton /tmp/simple_example $ od -tx1 -tc -N 8 tawny_out.png
0000000 c2 89 50 4e 47 0d 0a 1a
302 211 P N G \r \n 032
0000010
To copy to clipboard, switch view to plain text mode
Bookmarks