[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

Problems saving bitmap with proper vertical orientation (even though biHeight is negative)

Asked by PMH4514 in C++ Programming Language, Adobe Type Manager, Font Creator

Tags: bitmap, createdibsection, greater

I'm using the following code to save a buffer to a BMP file (the buffer and size info are in m_pData, and are all set properly). The saved images looks just fine except that it is flipped upside down. So I tried making the biHeight variable negative by multiplying the height by -1 (as is shown below). The problem then is that the saved image, when I try to open it with Paint, I see a message "bitmaps must be greater than one pixel on a side" - then I click OK and Paint opens, the image is the appropriate dimensions, but all white.

Any ideas? It's an 24bit color image of 1000x1000.  (the code is also intended to work with 8bit grayscale images, in which case the data in m_pData reflects 8bits and a size of 1000x1000 rather than 24 bits and 1000x1000x3)


-------------------

BITMAP bm = {0};
BITMAPINFO* pbmInfo = new BITMAPINFO;
ZeroMemory( pbmInfo, sizeof(*pbmInfo) );
pbmInfo->bmiHeader.biWidth = m_pData->width;    
pbmInfo->bmiHeader.biHeight = m_pData->height * -1;
pbmInfo->bmiHeader.biPlanes = 1;
pbmInfo->bmiHeader.biBitCount = m_pData->bitdepth;
pbmInfo->bmiHeader.biSizeImage = m_pData->size;
pbmInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmInfo->bmiHeader.biClrUsed = 0;
pbmInfo->bmiHeader.biClrImportant = 0;
pbmInfo->bmiHeader.biCompression = BI_RGB;

void *buffer = NULL;
HBITMAP hBmp = ::CreateDIBSection(0, pbmInfo, DIB_RGB_COLORS, &buffer, NULL, 0);
if (!hBmp)
  return false;

// Copy the image into the buffer.       
FILE *pFile = fopen(sPath, "wb");
if(pFile == NULL)
  return FALSE;

BITMAPFILEHEADER bmfh;
int nBitsOffset = sizeof(BITMAPFILEHEADER) + pbmInfo->bmiHeader.biSize;
LONG lImageSize = pbmInfo->bmiHeader.biSizeImage;
LONG lFileSize = nBitsOffset + lImageSize;
bmfh.bfType = 'B'+('M'<<8);
bmfh.bfOffBits = nBitsOffset;
bmfh.bfSize = lFileSize;
bmfh.bfReserved1 = bmfh.bfReserved2 = 0;

//Write the bitmap file header
UINT nWrittenFileHeaderSize = fwrite(&bmfh, 1, sizeof(BITMAPFILEHEADER), pFile);

//And then the bitmap info header
UINT nWrittenInfoHeaderSize = fwrite(&pbmInfo->bmiHeader, 1, sizeof(BITMAPINFOHEADER), pFile);

//Finally, write the image data itself
//-- the data represents our drawing
UINT nWrittenDIBDataSize = fwrite(m_pData->buffer, 1, lImageSize, pFile);

fclose(pFile);

 
Related Solutions
 
Loading Advertisement...
 
[+][-]05/19/05 01:11 PM, ID: 14040061Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C++ Programming Language, Adobe Type Manager, Font Creator
Tags: bitmap, createdibsection, greater
Sign Up Now!
Solution Provided By: Mercurius0
Participating Experts: 2
Solution Grade: A
 
[+][-]05/19/05 01:29 PM, ID: 14040202Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/19/05 01:37 PM, ID: 14040282Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/19/05 03:10 PM, ID: 14041043Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/19/05 08:18 PM, ID: 14042799Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/19/05 10:40 PM, ID: 14043190Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/20/05 05:18 AM, ID: 14044718Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93