Solved

DPI for jpeg or BMP

Posted on 2000-05-11
6
1,377 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:zwarte
Comment Utility
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
Comment Utility
Do what I do - use your customer/co-developer as the testbed :)
0
 
LVL 1

Author Comment

by:zwarte
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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":…

743 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

15 Experts available now in Live!

Get 1:1 Help Now