Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set DPI for QImage

Tags:

c++

text

dpi

qt

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).

like image 930
sashoalm Avatar asked Dec 09 '25 13:12

sashoalm


1 Answers

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.)

like image 108
Nikos C. Avatar answered Dec 12 '25 02:12

Nikos C.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!