troubleshooting Question

About CreateDIBSection?

Avatar of ken-nirvana
ken-nirvana asked on
Smartphone Programming
1 Comment1 Solution469 ViewsLast Modified:
Hi,
I'm new in windows graphics programmer,I need rotate a
bitmap 90 degress,I use CreateDibSection Crate a new
bitmap,but this bitmap can't be display, Who can help me?
------------------My Code Here------------------------
HBITMAP Rotate90(HDC hDC,HBITMAP hSrcBmp)
{
     DIBSECTION dib;
     HBITMAP hRotatedBmp;
     LPBITMAPINFO bi;
     //---Get source bitmap bits---//[8/31/2002]
     if(::GetObject(hSrcBmp,sizeof(DIBSECTION),&dib)
== NULL)
     {
          return NULL;
     }

     if(dib.dsBm.bmBitsPixel != 16 ||
dib.dsBm.bmPlanes != 1)
     {
          //---Only support 16bits bitmap?---//
[8/31/2002]
          return NULL;
     }

        LPBYTE lpSrcData = (LPBYTE)dib.dsBm.bmBits;
     ASSERT(lpSrcData);

     //---Create new dib for return---//[9/1/2002]
     DWORD dwSrcBytesPerLine = WIDTHBYTES
(dib.dsBm.bmBitsPixel * dib.dsBm.bmWidth);
     DWORD dwDestBytesPerLine = WIDTHBYTES
(dib.dsBm.bmBitsPixel * dib.dsBm.bmHeight);
     DWORD dwSize = dwDestBytesPerLine *
dib.dsBm.bmWidth;

     bi = (LPBITMAPINFO)GlobalAlloc(GPTR,sizeof
(BITMAPINFO) + 3*sizeof(RGBQUAD));
     memset(bi,0,sizeof(BITMAPINFO));
     memcpy(&bi->bmiHeader,&dib.dsBmih,sizeof
(BITMAPINFOHEADER));
     bi->bmiHeader.biHeight = dib.dsBm.bmWidth;
     bi->bmiHeader.biWidth = dib.dsBm.bmHeight;
     bi->bmiHeader.biSizeImage = dwSize;
     bi->bmiHeader.biClrUsed = 0;
     bi->bmiHeader.biCompression = BI_BITFIELDS;
     LPRGBQUAD pColorTable = bi->bmiColors;
     DWORD dw[3];
     dw[0] = 31744;  //RED bitmask  Bits: 0 11111 00000 00000
     dw[1] = 992;    //GREEN bitmask Bits:0 00000 11111 00000
     dw[2] = 31;     //BLUE bitmask  Bits:0 00000 00000 11111
     memcpy(pColorTable, dw, 3*sizeof(DWORD));

     
     //LPBYTE lpDestData = (LPBYTE)GlobalAlloc
(GPTR,dwSize);
     LPBYTE lpDestData = new BYTE[dwSize];
     memset(lpDestData,0,dwSize);

     //---start rotate---//[8/31/2002]
     for(int i = 0; i < dib.dsBm.bmHeight; i++)
          for(int j = 0; j < dib.dsBm.bmWidth; j++)
          {
               *(lpDestData +
(dwDestBytesPerLine * j + (dib.dsBm.bmHeight - i - 1)*2))
=
                    *(lpSrcData+
(dwSrcBytesPerLine*i+j*2));
               *(lpDestData +
(dwDestBytesPerLine * j + (dib.dsBm.bmHeight - i - 1)*2)
+ 1) =
                    *(lpSrcData+
(dwSrcBytesPerLine*i+j*2) + 1);
          }


     hRotatedBmp = CreateDIBSection(
          hDC,
          bi,
          DIB_RGB_COLORS,
          (void **)&lpDestData,
          NULL,
          NULL
          );

     return hRotatedBmp;
}
ASKER CERTIFIED SOLUTION
sujeeshlal

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros