?
Solved

DPI for jpeg or BMP

Posted on 2000-05-11
6
Medium Priority
?
1,387 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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