301 int depth = image.
depth();
308 writer.setQuality(94);
312 int width = image.
width();
313 int height = image.
height();
314 int size = width*height;
317 size = (width+7)/8*height;
326 memset(pixel, 0xff, size);
327 for(
int y=0; y < height; y++) {
329 for(
int x=0; x < width; x++) {
332 (*(s + (x >> 3)) >> (x & 7)) & 1 :
333 (*(s + (x >> 3)) << (x & 7)) & 0x80 ;
335 pixel[i >> 3] ^= (0x80 >> (i & 7));
339 i = (i+7) & 0xffffff8;
341 }
else if (depth == 8) {
342 for(
int y=0; y < height; y++) {
344 for(
int x=0; x < width; x++) {
347 pixel[i] = (
unsigned char)
qGray(rgb);
350 pixel[i] = (
unsigned char)
qRed(rgb);
351 pixel[i+1] = (
unsigned char)
qGreen(rgb);
352 pixel[i+2] = (
unsigned char)
qBlue(rgb);
358 for(
int y=0; y < height; y++) {
360 for(
int x=0; x < width; x++) {
363 pixel[i] = (
unsigned char)
qGray(rgb);
366 pixel[i] = (
unsigned char)
qRed(rgb);
367 pixel[i+1] = (
unsigned char)
qGreen(rgb);
368 pixel[i+2] = (
unsigned char)
qBlue(rgb);
Format
The following image formats are available in Qt.
char * data()
Returns a pointer to the data stored in the byte array.
The QByteArray class provides an array of bytes.
The QBuffer class provides a QIODevice interface for a QByteArray.
int qRed(QRgb rgb)
Returns the red component of the ARGB quadruplet rgb.
Format format() const
Returns the format of the image.
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
The QImageWriter class provides a format independent interface for writing images to files or other d...
int qGray(int r, int g, int b)
int depth() const
Returns the depth of the image.
int width() const
Returns the width of the image.
void resize(int size)
Sets the size of the byte array to size bytes.
int height() const
Returns the height of the image.
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageWriter.
int qGreen(QRgb rgb)
Returns the green component of the ARGB quadruplet rgb.
static QByteArray runlengthEncode(const QByteArray &input)
int qBlue(QRgb rgb)
Returns the blue component of the ARGB quadruplet rgb.
QRgb color(int i) const
Returns the color in the color table at index i.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
QByteArray ascii85Encode(const QByteArray &input)