Solved

DPI for jpeg or BMP

Posted on 2000-05-11
6
1,378 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
  • 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 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
In addition to being a great web-based presentation tool, Prezi also makes it easy to save your presentation as a PDF to share with others as well. Learn how in this tutorial. Select the share icon from the top menu in your Prezi editor: Select "D…
Learn how to use the remote presentation tool in Prezi to allow you to harness the power of this cloud based presentation platform. You can show your presentation with a remote audience using this free tool.

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now