Solved

Displaying bitmaps

Posted on 1998-09-22
12
277 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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