Setting dpi in ofImage

I was wondering if it’s possible to change the DPI setting for an ofImage? I’d like to be able to save it at 300dpi so I can print it at high resolution.

I guess my other option is to just use 72dpi and scale everything up.


DPI is a printing term and only makes any sense when you are specifying the size of the printed image. You could take a “72 DPI” jpg and print it at “300 DPI”, which would just mean the image would shrink to accommodate for the pixel printing density.

Moka made a great ofxTileSaver that allows you to save a rendered screen at high resolutions, but if you are loading in ofImages of a fixed resolution, then going larger than that will cause them to be filtered and stretched (which sometimes is not _too_ bad). Any openGL visuals will scale properly though.—high-resolution-opengl-screen-grabs/1783/0

Ok, thank you for the clarification Grimus. I was just thinking in terms of how Photoshop interprets the DPI and relates it to the image dimensions when you convert from inches to pixels.

I’ve got a solution now that’s printing nice, high resolution images. :slight_smile:

Hi @plong0,

Can you share your solution? I am facing a similar problem on Windows with my Yoga 2 Pro. Apparently there is a way on Mac to setup GLFW to enable Retina display mode but that doesn’t seems to work on Windows. So I am interested in knowing about your experience :smile:


I think we must clarify that DPI has nothing to do with pixel density (retina and others). I recently had to deal with that in mac:

pixelScreenCoordScale = ((ofAppGLFWWindow*)ofGetWindowPtr())->getPixelScreenCoordScale();

is this what does not work in windows?

Hi Jordi, @Jordi

Thanks for responding. As far as I can tell, the pixelScreenCoordScale is being calculated using the ratio framebufferW / window. Unfortunately, this ratio is always 1 even after activating the DPIAwareness on the executable manifest.

Any ideas?

It works for me in mac.
maybe the best would be to open an issue in openframeworks repo in github. Not sure if it has been tested in all platforms.

@Jordi Thanks… Actually I was checking the history yesterday and it seems like a glfw issue. Cheers


i am actually saving an image from an FBO and need to print it.
It is a polaroid like format but when i print it it fill the entire A4 page format even when forcing to native image format.

I loaded it into GIMP and saved it into 300 dpi and this now prints it in the right format.

as i understand i should scale the size up and print it in hi dpi ?

for example, i generate a 800x600 pixels image which is by default in 72 DPI
if i convert it in 300 DPI using GIMP i still have a 800x600 pixels image

when i print those images, the former is much bigger than the latter.

What i don’t understand is that both images are 800x600 pixels for the computer, so how scaling it in openFrameworks would “boost” the pixel density ?

but how do you achieve that ?

thanks a lot

@gallo the better way to approach this is to figure out what resolution is needed for the fbo so that you do as little scaling as possible for print. 800x600 is aprox 68 dpi ( dots per inch ) if printed on A4 which is 11.69 inches on the long side.

800 pixels / 11.69 inches = 68 dpi

So you can work back from this approach. 300 dpi is usually recommended for print.
So: 300 dpi * 11.69 inches = 3507 pixels

So rounding down a bit you could do 3000 pixels x 2250 to have the same aspect ratio of 800x600 and close to a 300 dpi image, which you can safely scale to fit your print media.

You could also try with half this resolution. You often don’t need 300 dpi it depends a lot on the paper you are using, the printer and the content you are printing.

Hope that helps.

@Gallo, everything what @theo said.

But, if for some reason, you want to automate the printing process, without having to create scripts/actions in Photoshop or whatever app you use to print, you can simply grab the code that saves the image in ofImage.cpp and add:

FreeImage_SetDotsPerMeterX(bmp, 11811);
FreeImage_SetDotsPerMeterY(bmp, 11811);

Before saving the image (for exemple, after line 343).

Mind that it’s dots per meter and not dots per inch. So 300 DPI is 11811 DPM. So, a 1 / 39.37007874016 ratio, just to be very very very specific. :slight_smile:

(post: @arturo, should this be implemented? defaults to 72, as already is, but there’s a option to change?)

Hi all,

Thanks a lot for your suggestions.

For the record, here is what i am doing :

  • grab a picture fro a webcam (800x600 area cropped from HD)
  • add it to an FBO composited with some other materials
  • save the FBO into a image file
  • print the composit image

Printing is done with system level command “lp”
Maybe there is another way ? i found this one simple enough for now.
The thing is : how to tell the printer to print in 300 DPI ?
As i said, printing 800x600 in 72 DPI covers almost the whole A4 format while printing the same in 300 DPI prints 1/6th the size

should i save the image to 3000 x 2250 and then force print to smaller size ?

system("lp -o Media=800x600 -o ColorModel=Gray ./bin/data/test.jpg");

also PNG printing doesn’t work (blank paper) but that is certainly another story :slight_smile:

You can use that command, but you can’t tell the printer the DPI. That’s on the image metadata itself. You would need to follow my previous suggestion.

But, I think you can scale the image when printing from the command line. So if you output 3000 x 2250 at 72 DPI, you need to do “scaling=24”. You’ll need to check/test.

Just to be clear, DPI is metadata for printing. An image with 800 x 600 pixels, as 800 x 600 pixels regardless of it’s DPI. If you change it’s DPI, it displays the same because that info is ignored. So, just ignore those tutorials online that say that you “need” to save at 72 DPI for the internet or whatever.

Btw, why the 72 DPI stigma? Because Apple was pushing the printer in the 80’s and their monitors had 72 DPI. So, when you printed, you had an 1:1 ratio.

yes it seems i can scale when printing. i wonder if the printing scale is the same as scaling in GIMP (destructive).

I still need to do some tests though.

yes i guess we could have a settings object for saving so you could specify something like this along with the file name, the image type, compression quality…

@arturo should we file a request somewhere ?

Ok for the FBO.
Now how to deal with the camera capture ? should i resize it before drawing the captured frame into the FBO ?

Sounds like a bit different as the result image could be a bit blurry due to the scale factor ?

I think in this case because the source image is a camera there isn’t much point using a large FBO.
Probably easier to just resize the image before saving to a size that produces the right print res or maybe explore some of the lp commands.

-o fit-to-page

looks like it will scale the image to fit the page.

Thanks Theo !

I just tried the solution provided by Hubris.
It seems the best and easier solution so far. But it really produces a 800x600 pixels image at 300 DPI and printing it like that is pretty straightforward.

Too bad this needs a core hack :slight_smile:

I will keep digging other solutions using OS level commands and test a bit more.

thanks all