From kde-devel Wed Aug 27 01:30:35 2008 From: James Richard Tyrer Date: Wed, 27 Aug 2008 01:30:35 +0000 To: kde-devel Subject: Re: QImage conversion functions Message-Id: <48B4AE3B.2000603 () acm ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=121980071322971 David Johnson wrote: > On Tuesday 26 August 2008 12:49:44 pm David Johnson wrote: >> QImage likes to keep stuff in its own internal format, so for example when >> you scale the image you lose the mono format. Reordering your operations >> fixed most things. What isn't fixed is the bit depth of the saved image. I >> think this is just how QImage saves TIFF images. When you save as PNG you >> get 1 bit depth. > > Here's the code I meant to attach: > > #include > #include > > int main() > { > QImage img = QImage("image.png"); > int newHeight= img.height()*2; > int newWidth= img.width()*2; > img = img.scaled(newWidth, newHeight, Qt::KeepAspectRatio, > Qt::SmoothTransformation); > img = img.convertToFormat(QImage::Format_Mono, Qt::MonoOnly); > img.setDotsPerMeterX(150*39); //150 dpi > img.setDotsPerMeterY(150*39); //150 dpi ARGH! Small problem is that although you can convert Dots Per Meter exactly to Dots Per Inch (although not always an integer) the reverse is not true. The best you can do is to use more exact conversion: > img.setDotsPerMeterX(5906); //150 dpi > img.setDotsPerMeterY(5906); //150 dpi There might be an issue with interference. If this is a problem, try 5905. I consider the inability to set Dots Per Inch a bug since if you start with an image that is DPI, conversion to DPM can cause problems. > qDebug() << img.depth(); > img.save("output.tif", "tiff", 100); > img.save("output.png", "png", 100); > } > -- JRT >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<