DPI for jpeg or BMP

How do I set the dpi ratio for a jpg or a bitmap?
I already found the pixelformat that sets the bitratio, but I can't figure out how that would correspond to the pixelformat or whatever.
BTW : I need 72Dpi jpg's
Who is Participating?
sburckConnect With a Mentor Commented:
For a BMP, the file header looks like this:

typedef struct tagBITMAPFILEHEADER { // bmfh  
        WORD    bfType;
        DWORD   bfSize;
        WORD    bfReserved1;
        WORD    bfReserved2;
        DWORD   bfOffBits;

Followed immediately by:

typedef struct tagBITMAPINFOHEADER{ // bmih  
   DWORD  biSize;
   LONG   biWidth;
   LONG   biHeight;
   WORD   biPlanes;
   WORD   biBitCount
   DWORD  biCompression;
   DWORD  biSizeImage;
   LONG   biXPelsPerMeter;
   LONG   biYPelsPerMeter;
   DWORD  biClrUsed;
   DWORD  biClrImportant;

The information you want to stick in is the biXPelsPerMeter, and the biYPelsPerMeter.  These are at a fixed offset of 38 and 42 bytes into the file, respectively.  They are in pixels per meter, not per inch, so you'll have to scale your 72 DPI to 2834 DPM (I think, if I calculated it right), and put this signed longint value at these offsets.  You can treat your BMP file as a binary file to do this.
If you are doing this to your printer, and since you already know two things:

1)  How many pixels wide & high your image is.
2)  How large you want your printout to be.

All you do is call StretchDraw of the TBitmap you are outputting to Printer.TBitmap to the size you want.

DPI is always a hardware dependency.  You really shouldn't care how many pixels are in your JPEG, but you want to display them at a given size - that is the important factor.  The only time you will really care about the number of pixels you have in the image is (1)  there are far too few, and the image is grainy, or (2) there are far too many, and the time and space needed to deal with them is too much.

zwarteAuthor Commented:
just got some more info on the DPI thing which I thought contained the number of pixels that were saved.
apparently it is only a setting in the header of your bmp file, telling your printer how large he must print this thing to its canvas. As SBurck points out I can manually resize my bmp to the printers canvas, but unfortunatly I only create the bitmap and I don't use it. The people that use it want it to contain this info in the headerfile so my question would then be  : how do I get this setting into the headerinfo of the bmp-file

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

zwarteAuthor Commented:
okay, that sounds like a good answer,
now I'm just having to find myself a nice independent program that can actually verify that my changes were succesfull (I tried Paint Shop  Pro 4.0 and paint, but they gave me all the info I didn't need :-(
of course I could write one myself, but that would make me always right ;-)

Hang on a bit an the points are yours ;-)

already tnx a lot for the help

Do what I do - use your customer/co-developer as the testbed :)
zwarteAuthor Commented:
Hi SBruck,

Sorry about the long delay,
I'm still looking for some kind of way to actually test this, 'cause all the programs I use seem to autoscale, and the contracter dropped the feature, due to the fact that it indeed was a useless enhancement. However I already did get confirmation that this was the way to do it (if someone would need it), so the points are yours and your time was not spent in vain ;-)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.