Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DPI for jpeg or BMP

Posted on 2000-05-11
6
Medium Priority
?
1,389 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:zwarte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:sburck
ID: 2800191
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.

0
 
LVL 1

Author Comment

by:zwarte
ID: 2800333
mmm...
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

Tom,
0
 
LVL 3

Accepted Solution

by:
sburck earned 200 total points
ID: 2800470
For a BMP, the file header looks like this:

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

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;
} BITMAPINFOHEADER;

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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:zwarte
ID: 2800665
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

Tom,
0
 
LVL 3

Expert Comment

by:sburck
ID: 2800684
Do what I do - use your customer/co-developer as the testbed :)
0
 
LVL 1

Author Comment

by:zwarte
ID: 2840459
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 ;-)

Tom,
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question