Solved

Displaying bitmaps

Posted on 1998-09-22
12
282 Views
Last Modified: 2013-12-03
I have tried various ways of displaying resource bitmaps, including the CDib class by D. Kruglinski. All of them produce low-quality results: horizontal lines missing or doubled, and VERY jagged text. I assume this is the result of mapping to the screen. I have tried changing to HIENGLISH; that changes the appearance but does not really help. Full credit to anyone who can point to an example that solves this problem.
0
Comment
Question by:therkex
  • 8
  • 3
12 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1173415
The problem is the palette if you're sticking the bitmaps into dialogs etc.  There's infact to aspects to this

(i) You need to realize the palette when displaying the bitmap
(ii) You need to make sure the bitmap is really X number of colors in the original (VC tends to convert bitmaps down to 16 bit so manually add the reference to the bitmap file by editing the .RC file in text mode)

I don't know know that the class library refered to, but I suspect it does number (i), therefore you need to work on (ii) I think
0
 
LVL 22

Expert Comment

by:nietod
ID: 1173416
Why palette?  It should like it is a scalling issue.  Missing lines indicate the image is being scalled down and jagged lines indicate it is being scalled up.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1173417
I would get the bitmap's dimenssions and then draw the bitmap at those dimensions using the MM_TEXT mapping mode.
0
 
LVL 22

Accepted Solution

by:
nietod earned 500 total points
ID: 1173418
For example,

HBITMAP BitMapHnd = LoadBitmap(GetModuleHandle(NULL),BitMapNam);
BITMAP BitMap;
GetObject(BitMapHnd,sizeof(BITMAP),&BitMap);
BitBlt(DscDC,DstX,DstY,BitMap.bmWidth,BitMap.bmHeight,MemDC,0,0,SRCCPY);


0
 
LVL 22

Expert Comment

by:nietod
ID: 1173419
If this does not help, please post your code.  

(sorry for these sporatic messages, but expoerts exchangeis having technical difficulties.)
0
 

Author Comment

by:therkex
ID: 1173420
Thanks, I will try the MM_TEST suggestion.
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 22

Expert Comment

by:nietod
ID: 1173421
It might be a typo on your part, but just to make sure, that is MM_TEXT not MM_TEST.  In that mapping mode dimensions are expressed in pixels.  Since the height and width of the bitmap are returned in pixels, it makes it easy to draw the bitmap in its desired height and width.
0
 

Author Comment

by:therkex
ID: 1173422
The MM_TEXT suggestion worked for the screen (except that text is still ugly), indicating that it is a scaling problem, as you thought. The problem now is that it is scaled differently when printed. Also, (of course) it doesn't scale as the rest of the drawing does when the user changes the size of the window. My application draws its screen using scaled functions, so that when the screen size is changed, the size of the image follows it. Maybe this is not what bitmap drawing functions are for, but isn't that what StretchBlt is for?


0
 
LVL 22

Expert Comment

by:nietod
ID: 1173423
Well, its not exactly a problem.  For a bitmap to look good, you have to draw it unscaled, that is, each pixel in the source (original bitmap) has to be mapped to one pixel in the destination (screen/printer).  If you do that it looks like it did when it was drawn.  On the other hand, if you make the destination larger than the original bitmap, then some of the pixels in the sourece will be mapped to multiple pixels in the destination, that makes the bitmap look chunky or jagged.  This happens, for example, when you take a bitmap that is 100 pixels across and draw it so it is 200 pixels across.  Each pair of pixels in the final result will be identical as they were mapped from one pixel in the source.  On the other hand if you make the destination smaller than the source, some pixels in the source won't be mapped at all.  For example, if you take a 100 pixel wide bitmap and draw it 50 pixels wide, then every other pixel will be missing.

There is nothing that can be done about this with bitmaps.  Your choices are to scale them to a desired size (in real world units, like 1 inch across)  and leave with their chunky appearance, or to display them in their created size.  Which may be an awkward size.

continues.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1173424
What can you do about this?  Well, you can provide your program with the bitmaps in a variety of sizes.  Then when you need a bitmap of a particular physical size (inches, not pixels), you find the bitmap that will be closest to that size when drawn not scaled.  That is an okay solution, and one that I use, when bitmaps are absolutely necessary.  Another solution is to not use bitmaps.  Like you (and unlike everyone else) I have a scallable user interface and bitmaps for buttons and scrollbars etc just look terrible (I support them, but don't use them myself)  Instead I use polygons for simple shapes.  for example, menu check marks, left and right arrow buttons, etc can be represented as a polygon.  Since the polygon is a mathematical construct, it can be scaled to any size and drawn smoothly.  For images that can't be represented as a polygon you can use meta files(I actually haven't done this part yet, but I have an intern working on it at this very moment).  a metafile is an alternative to a bitmap for storing images.  It stores the image in terms of a series of mathematically defined drawing operations.  Like make a line from point x to point y then may a circle of radius z at point A, etc.  Again, like a polygon these can be scaled and remain smooth.

What I have done is to create an image class hierarcy.  I have a base class and derive classes for bitmaps and polygons and eventually metafile images.  Then I can draw an image the same way regardless of the nature of the image.  Another advantage of this class system is that I can convert any of the image types to a bitmap image.  This is nice because bitmaps are drawn much more quickly than polygons and metafiles (in general).  So what I do is scale the other image types to the desired size and them create a bitmap from them.  

Does that help?
0
 

Author Comment

by:therkex
ID: 1173425
Thanks for the help. I now feel like I have a good idea where bitmaps fit in the scheme of things. Are you aware of any third-party support for metafile operation?

Thanks again...Eric Therkelsen (therk@etts.com)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1173426
I'm not sure what you mean by "support"  Do you mean programing libraries for dealing with them, programs for generating them, or I don't know?
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

Title # Comments Views Activity
Grammars for C C++ and java 1 113
c++ getting the first 10 characters of a char* string 11 90
True Type Font Files? 4 82
Arduino EDI - Programming language 3 80
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

912 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

21 Experts available now in Live!

Get 1:1 Help Now