Code: Select all
Magick::Image* TgaFileType::toImage(QImage& qimage)
{
Magick::Image *newImage ;
double scale = 1 / 255.0;
Magick::PixelPacket *pixels;
Magick::ColorRGB mgc;
newImage = new Magick::Image(Magick::Geometry(qimage.width(), qimage.height()), Magick::ColorRGB(0.5, 0.2, 0.3));
newImage->modifyImage();
for (int y = 0; y < qimage.height(); y++) {
pixels = newImage->getPixels(0, y, newImage->columns(), 1);
for (int x = 0; x < qimage.width(); x++) {
QRgb pix = qimage.pixel(x, y);
mgc.red( scale*qRed(pix) );
mgc.green( scale*qGreen(pix) );
mgc.blue( scale*qBlue(pix) );
mgc.alpha( scale*qAlpha(pix) );
*pixels++ = mgc;
}
newImage->syncPixels();
}
return newImage;
}
Code: Select all
qimage.save(dstFilename)
Code: Select all
Magick::Image* image = toImage(*imgOriginal);
image->write(dstFilename);
Code: Select all
mgc.alpha( 0 );
How can I set alpha values to produce a transparent Targa image?