Solved

Bitmap problems.....

Posted on 1999-01-27
10
316 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Dynamically allocate memory 9 62
How to print into std::string like sprintf using C++11? 12 81
object oriented programming comparison 5 77
I could not set window to top 4 20
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…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

856 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