Solved

DPI Problem While Opening And Saving Bitmap

Posted on 2000-04-20
8
520 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
[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
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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