[gdal-dev] help me

liu_daojie liu_daojie at 163.com
Fri Sep 26 11:31:10 EDT 2008


 hello:
  the following code,can not show tif:
void CTrans::DrawImage1(void)
{  
  m_pMemoryDC->SelectObject(m_pMemoryBitMap);
  CRect rc(0,0,m_pViewWidth,m_pViewHeight); 
  CBrush brush(RGB(255,255,255));
     m_pMemoryDC->FillRect(rc,&brush); 
  if( poDataset != NULL ) 
  {
 
   GDALRasterBand *poBand1;   //Ò£¸ÐµÄÒ»¸ö²¨¶Î
   GDALRasterBand *poBand2;
   GDALRasterBand *poBand3;
   int nBandCount;
   nBandCount=poDataset->GetRasterCount();
   poBand1=poDataset->GetRasterBand(1);
   poBand2=poDataset->GetRasterBand(2);
   poBand3=poDataset->GetRasterBand(3);
   
   if (poBand1!=NULL && poBand2 != NULL &&poBand3!=NULL)  
   {
   
   //»ñȡͼÏñµÄ³ß´ç
   //»ñȡͼÏñ´°¿Ú³ß´ç
    
   
   int nImgSizeX=poDataset->GetRasterXSize();
   int nImgSizeY=poDataset->GetRasterYSize();
   
   int nBufferSizeX,nBufferSizeY;
   
   nBufferSizeX = nImgSizeX;
   nBufferSizeY= nImgSizeY;
   
   
   
   BYTE *pafScanblock1,*TempLock1;
   BYTE *pafScanblock2,*TempLock2;
   BYTE *pafScanblock3,*TempLock3;
   
     pafScanblock1 = (BYTE *) CPLMalloc((nBufferSizeX)*(nBufferSizeY));
   pafScanblock2 = (BYTE *) CPLMalloc((nBufferSizeX)*(nBufferSizeY));
   pafScanblock3 = (BYTE *) CPLMalloc((nBufferSizeX)*(nBufferSizeY));
   
   TempLock1 = pafScanblock1;
   TempLock2 = pafScanblock2;
   TempLock3 = pafScanblock3;
   
   poBand1->RasterIO( GF_Read, 0, 0,nBufferSizeX,nBufferSizeY, 
    pafScanblock1,nBufferSizeX,nBufferSizeY, GDT_Byte,0, 0 );
   
   poBand2->RasterIO( GF_Read, 0, 0,nBufferSizeX,nBufferSizeY, 
    pafScanblock2,nBufferSizeX,nBufferSizeY, GDT_Byte,0, 0 );
   
   poBand3->RasterIO( GF_Read, 0, 0,nBufferSizeX,nBufferSizeY, 
    pafScanblock3,nBufferSizeX,nBufferSizeY, GDT_Byte,0, 0 );  
   //ÔÚViewÖðµãÏÔʾͼÏñ
   DWORD dwBytes = (nBufferSizeX * 24) / 8; 
   while(((DWORD) dwBytes) % 4) 
   {
    dwBytes++;
   }
   
   BYTE *szBuffer = new BYTE[nBufferSizeY*dwBytes];
   memset(szBuffer,0,nBufferSizeY*dwBytes);
   BYTE *pTemp = szBuffer; 
   int nIndex = 0;
   for (int i=0;i<nBufferSizeY;i++)
   {
    for (int j=0;j<nBufferSizeX;j++)
    {
    
     BYTE dn1=*pafScanblock1;
      BYTE dn2=*pafScanblock2;
         BYTE dn3=*pafScanblock3;
       
     memcpy(szBuffer,(char*)(&dn3),1);
     szBuffer+=1;
     memcpy(szBuffer,(char*)(&dn2),1);
     szBuffer+=1;
     memcpy(szBuffer,(char*)(&dn1),1);
     szBuffer+=1;
     pafScanblock1++;
     pafScanblock2++;
     pafScanblock3++;
     
    }
    
    szBuffer = pTemp+dwBytes*i;
    
   }
   CPLFree(TempLock1);
   CPLFree(TempLock2);
   CPLFree(TempLock3); 
   
   BITMAPINFOHEADER bmiHdr;
         BITMAPINFO MapInfo;
         memset(&bmiHdr, 0, sizeof(BITMAPINFOHEADER));
         bmiHdr.biBitCount = 3*8;
         bmiHdr.biClrImportant = 0;
         bmiHdr.biClrUsed = 0;
         bmiHdr.biCompression = BI_RGB;
         bmiHdr.biHeight = -nBufferSizeY;
         bmiHdr.biPlanes = 1;
         bmiHdr.biSize = sizeof(BITMAPINFOHEADER);
         bmiHdr.biSizeImage = 0;
         bmiHdr.biWidth = nBufferSizeX;
 
         bmiHdr.biXPelsPerMeter = 0;
         bmiHdr.biYPelsPerMeter = 0;
 
         MapInfo.bmiHeader = bmiHdr;
         MapInfo.bmiColors[0].rgbBlue = 0;
         MapInfo.bmiColors[0].rgbGreen = 0;
         MapInfo.bmiColors[0].rgbRed = 0;
         MapInfo.bmiColors[0].rgbReserved = 0;
 
  //dc.SetStretchBltMode(COLORONCOLOR);
         StretchDIBits(m_pMemoryDC->GetSafeHdc(), 0, 0, nBufferSizeX,nBufferSizeY,//nScrrenWidth, nScrrenHeight,
    0, 0, bmiHdr.biWidth, -bmiHdr.biHeight,
    pTemp, (LPBITMAPINFO)(&MapInfo), DIB_RGB_COLORS, SRCCOPY);
    
    GDALClose(poDataset);
   delete []pTemp;  
   }
  }
 
} 
where are wrong?
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20080926/5bc03f4d/attachment.html


More information about the gdal-dev mailing list