Solved

Bitmap problems.....

Posted on 1999-01-27
10
307 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

758 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

18 Experts available now in Live!

Get 1:1 Help Now