Solved

Bitmap problems.....

Posted on 1999-01-27
10
310 Views
Last Modified: 2010-04-16
We have a program that takes an image from a CCD camera and analyzes it as well as displays it. This program works fine on our initial computer and on our server with archived data (no camera).

We have just expanded new computers and camera, however this code refuses to display the images on the new computers. It does get the data though, as the analysis are still correct. Perhaps someone can see a flaw that we are missing....

All computers are running NT (3 workstation and 1 Server) the two that will not display are running Workstation.

Here is the peice of code that should display. It generates no errors and there are no problems when stepped through in debug mode.

//bitbuffer - 262144 bytes of data
Bitmap = new CBitmap;
Bitmap->CreateBitmap( 512, 512, 1, 8, bit_buffer);
Bitmap->SetBitmapBits(8*512*512, bit_buffer);
      
if(Bitmap != NULL)
{
   CDC memoryDC;
   memoryDC.CreateCompatibleDC(&dc);
   memoryDC.SelectObject(Bitmap);
      
   dc.SetStretchBltMode(COLORONCOLOR);
   if (Palette)
   {
       dc.SelectPalette(Palette, false);
       dc.RealizePalette();
       memoryDC.SelectPalette(Palette, false);
   }
   dc.BitBlt(10,10,512,512, &memoryDC, 0,0, SRCCOPY);
   ReleaseDC(&memoryDC);
}

Thanks for your help!
0
Comment
Question by:antelope
  • 4
  • 3
  • 3
10 Comments
 

Author Comment

by:antelope
ID: 1185333
Edited text of question
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185334
Hmm - you didn't detect any problems because you didn't check whether tthe relevant operations failed ... the code looks good at first glance. You might want to try

   if (!dc.BitBlt(10,10,512,512, &memoryDC, 0,0, SRCCOPY))
      {
        char acError[ ERROR_MAX];

        wsprintf ( acError, "BitBltFailed(), reason: %d", GetLastError());
        MessageBox ( NULL, acError, "Error!", MB_OK | MB_ICONSTOP);
      }

0
 
LVL 22

Expert Comment

by:nietod
ID: 1185335
I see some problems, not necessarily THE problem.

I think the ReleaseDC(&memoryDC); is wrong.  I beleive that MFC releases the DC when the DC is destroyed.  So this may cause it to be released a 2nd tim.e

The SelectObject and SelectPalette functions are not saving the previous bitmap or palette.  That is a serious error.  The previous bitmap and pallette must be saved AND must be selected back in before the DC is destroyed and before the bitmap or palette is destroyed.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1185336
Is the DC compatible with an 8 bits per pixel bitmap?  If the DC is for the screen and the screen is not in 256 color mode, that could be the problem.  If that is the case, consider using a DIB instead.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185337
'ReleaseDC(&memoryDC);' definitely is wrong and will return an error code, you should better use 'memoryDC.ReleaseOutputDC()' if you want to explicitly release it...
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: 1185338
But won't it be released automatically when the CDC is destroyed (it is a local)?  The docs don't mention a destructor and I don't use it, but I would HOPE that it would be.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1185339
Actually, CDC::~CDC() even calls ::DeleteDC() ;-)
0
 

Author Comment

by:antelope
ID: 1185340
nietod:

Thanks!! It was the 256 color display that was the problem, we were setup for true color....

If you want to submit it as an answer I can give you the points...

Thanks again
Antelope
0
 
LVL 22

Accepted Solution

by:
nietod earned 250 total points
ID: 1185341
Well changing the screen to 256 color is one solution, but not a good one.  You probably don't want to require that users run in a particular mode, right?  (Although I expect that this program isn't for distribution--I did imaging programming for a observatory once.)   A better solution is to switch to using device indipendant bitmaps (DIB).  This would allow you to display regardless of the screen's color mode (and other factors).  This may be a little more work, but is the "proper" way to deal with images like this.

Let me know if you have questions about this.
0
 

Author Comment

by:antelope
ID: 1185342
Thanks nietod...may take you up on that offer in the future...
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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

919 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

12 Experts available now in Live!

Get 1:1 Help Now