Solved

Displaying bitmaps

Posted on 1998-09-22
12
295 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
[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
  • 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
Independent Software Vendors: 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!

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

688 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