sashoalm
sashoalm

Reputation: 79467

Set DPI for QImage

I'm drawing text using QPainter on a QImage, and then saving it to TIFF.

I need to increase the DPI to 300, which should make the text bigger in terms of pixels (for the same point size).

Upvotes: 2

Views: 5294

Answers (2)

fyngyrz
fyngyrz

Reputation: 2658

There are 39.37 inches in a meter. So:

Setting:

qimage.setDotsPerMeterX(xdpi * 39.37);
qimage.setDotsPerMeterY(ydpi * 39.37);

Getting:

xdpi = qimage.dotsPerMeterX() / 39.37;
ydpi = qimage.dotsPerMeterY() / 39.37;

Upvotes: 1

Nikos C.
Nikos C.

Reputation: 51832

You can try using QImage::setDotsPerMeterY() and QImage::setDotsPerMeterX(). DPI means "dots per inch". 1 inch equals 0.0254 meters. So you should be able to convert to dots per meter (dpm):

int dpm = 300 / 0.0254; // ~300 DPI
image.setDotsPerMeterX(dpm);
image.setDotsPerMeterY(dpm);

It's not going to be exactly 300DPI (it's actually 299.9994), since the functions only work with integral values. But for all intents and purposes, it's good enough (299.9994 vs 300 is quite good, I'd say.)

Upvotes: 10

Related Questions