Solved

DPI Problem While Opening And Saving Bitmap

Posted on 2000-04-20
8
507 Views
Last Modified: 2013-12-03
Hi Experts,
        I am working in platformsdk using win32 api's. I have opened an already existing bitmap and displayed it, using the functions. Through this application you can also create a bitmap and can save it to the hard disk.
 
hdc=GetDC(mainwindow)
hdcbitmap=CreateCompatibleDC(hdc)

and then selecting the bitmap in hdcbitmap using SelectObject and displayed it using StretchBlt.

While printing bitmap I think I will use PrinterDC instead of display device context DC in each of the above function.
 
The problem is the bitmap which is 300 dpi normally, comes to 72 dpi in my application when I opened it or when I save a bitmap made through my application, the reason may be because monitor dpi is 72 and I have used CreateCompatibleDC function with the display device everywhere except while printing. Now I want when I open or save Bitmap in the application using the above functions it should come in 300 dpi only as this is original and then it can be displayed or printed, for this what I have to do.
 
I suppose instead of CreateCompatibleDC(displaydevice) I have to use CreateCompatibeDC(printerdevice). Is it so.

Also if I will open bitmap like this can it be displayed on the screen apart from going to the printer as this is necessary.
 
If I am wrong in what I think then what is the solution for my problem.
 
Thanks
Rahul

0
Comment
Question by:sudhaom
  • 4
  • 4
8 Comments
 
LVL 23

Expert Comment

by:chensu
Comment Utility
A bitmap has no such an attribute as DPI. Instead, DPI refers to a device.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
What is your question really?
0
 
LVL 1

Author Comment

by:sudhaom
Comment Utility
Ok I will explain the question again

Say in my hard disk there is a bitmap with name test1.bmp. This bitmap when I open in Photoshop in IMAGE ATTRIBUTES there comes,

900 width (in pixels)
600 width (in pixels)

PRINT SIZE Option (in the same dialog box), it comes
6 inch by 4 inch.
Resolution 300 dpi.

Now I have made an application that can open bitmaps and after making few changes in them U can save it back. Suppose I opened test1.bmp and after changing it a bit I save the changed one with the name test2.bmp .

Now I open test2.bmp in Photoshop, now see in IMAGE ATTRIBUTES there comes,

900 width (in pixels)
600 width (in pixels)

PRINT SIZE Option (in the same dialog box), it comes ................... THE PROBLEM PART HERE
12.5 inch by 8.333 inch.
Resolution 72 dpi.

Now when I will print test1.bmp it will come in 6 by 4 inch on a paper, the same bitmap (width height and everything) test2.bmp when I print will come in 12.5 by 8.333 inch on a paper as there is a difference in DPI. Paintbrush make images with 96 DPI. Though I know DPI is related with DEVICES not with bitmaps but there is something in different different applications as in my application (72 DPI)  or paintbrush (96 DPI) or photoshop (it can make 72,150 etc. any DPI bitmap) which is effecting the DPI's and therefore the Print size related with the bitmaps.

There is no difference between the Height,Width,Quality,Size etc in any bitmaps.

According to me I have a concept but that is right or not I don't know. I am opening bitmap with the function

CreateCompatibleDC(hdc) where is HDC is display device (monitor) handle. (NOTE MONITOR DPI IS 72)
that's why a a 300 dpi bitmap is now 72 dpi bitmap.

I suppose instead of screen hdc if I use printerDC (whose DPI is set to 300) in the function CreateCompatibleDC(hdc), the bitmap will not be effected and the problem can be solved 300 dpi remains 300 dpi. But then I fear after doing so WILL THAT BE BITMAP DISPLAYED AND MANIPULATED PROPERLY ON THE SCREEN, as VIEWING the bitmap on the screen can also not be ignored.
0
 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
Comment Utility
When you save the bitmap, you may specify the following two member variables of the BITMAPINFOHEADER structure.

biXPelsPerMeter
Specifies the horizontal resolution, in pixels per meter, of the target device for the bitmap. An application can use this value to select a bitmap from a resource group that best matches the characteristics of the current device.

biYPelsPerMeter
Specifies the vertical resolution, in pixels per meter, of the target device for the bitmap.

Take a look at what the original values are.
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:sudhaom
Comment Utility
Thanks Chensu I will try this out today and let U know by tomorrow.


Thanks
0
 
LVL 1

Author Comment

by:sudhaom
Comment Utility
Thanks Chensu I will try this out today and let U know by tomorrow.


Thanks
0
 
LVL 1

Author Comment

by:sudhaom
Comment Utility
Yes U are right Chensu,

The original values for

bih.bixPelspermeter and
bih.bixPelspermeter was 11808 (pixels per meter) that is 300 DPI

and when I opened the BMP it goes to 2834 that is 72 DPI.

Thanks for you great effort
But one more critical problem has arrived if possible for U hel me

See in my application when a user save the image created like paintbrush it goes into two formats BMP and JPG. For BMP the problem is solved as described by you. Now for JPEG Microsoft doesn't support JPEG format for NT 4.0 that's why I used FREE INTEL JPEG LIBRARY FUNCTIONS.

The function used by this library takes information from the bitmapinfo structure only, but when the JPGWRITE function is called it saves the JPG with 72 DPI though the bitmap is 300 DPI

If U can help me in any possible way I will be very thankful as this is very urgent and important for me.

Thanks
Rahul
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
I am not familiar with JPEG file format. I am not sure if there are such attributes as DPI. Apparently, the JPEG library functions ignore the attributes of BMP. I would suggest you look into all the functions the library provides to see if there is something to set.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

10 Experts available now in Live!

Get 1:1 Help Now