Solved

DPI Problem While Opening And Saving Bitmap

Posted on 2000-04-20
8
517 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
ID: 2735474
A bitmap has no such an attribute as DPI. Instead, DPI refers to a device.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2735479
What is your question really?
0
 
LVL 1

Author Comment

by:sudhaom
ID: 2739967
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 23

Accepted Solution

by:
chensu earned 150 total points
ID: 2740369
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
 
LVL 1

Author Comment

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


Thanks
0
 
LVL 1

Author Comment

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


Thanks
0
 
LVL 1

Author Comment

by:sudhaom
ID: 2743454
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
ID: 2744111
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 Scheduled Tasks 11 98
SQL to ElasticSearch Query 1 702
C# LINQ ForEach() question 6 54
Infrastructure development vs software development 3 60
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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