[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Displaying bitmaps

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
therkex
Asked:
therkex
  • 8
  • 3
1 Solution
 
Answers2000Commented:
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
 
nietodCommented:
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
 
nietodCommented:
I would get the bitmap's dimenssions and then draw the bitmap at those dimensions using the MM_TEXT mapping mode.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nietodCommented:
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
 
nietodCommented:
If this does not help, please post your code.  

(sorry for these sporatic messages, but expoerts exchangeis having technical difficulties.)
0
 
therkexAuthor Commented:
Thanks, I will try the MM_TEST suggestion.
0
 
nietodCommented:
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
 
therkexAuthor Commented:
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
 
nietodCommented:
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
 
nietodCommented:
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
 
therkexAuthor Commented:
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
 
nietodCommented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 8
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now