[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: QImage conversion functions
From:       James Richard Tyrer <tyrerj () acm ! org>
Date:       2008-08-27 1:30:35
Message-ID: 48B4AE3B.2000603 () acm ! org
[Download RAW message or body]

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 <QDebug>
> #include <QtGui>
> 
> 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 <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic