GDAL中的create方法好像要自己往里写参数,如何获取源图像的参数并写入呢?
因为我只对tiff文件中的象素做处理,不处理那些参数。
------解决方案--------------------
倒!你真懒,
和读取是差不多的,就是把GF_Read改成GF_Write就差不多了
我这一阵心情不错,给你个例子吧。
建议你还是系统的看看GDAL的官方说明及示例。
- C/C++ code
//第1段 读取原来参数 GDALDataset *poDataset; poDataset = (GDALDataset *)GDALOpen(path,GA_ReadOnly); int nbandcount=poDataset->GetRasterCount();//波段数目 int imgWidth = poDataset->GetRasterXSize();//文件X方向像素宽度 int imgHeight = poDataset->GetRasterYSize();//Y方向宽度 double tifCoord[6]; poDataset->GetGeoTransform(tifCoord);//地理范围参数 .... //第2段 写文件 GDALDataset *poDstDS; GDALDriver *poDriver ; char **papszOptions2 = NULL; const char *pszFormat = "GTiff"; poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); ...............此处添加自己的代码,比如设定路径,要建立的文件长度、宽度之类的 poDstDS = poDriver->Create( strFullPath, nPicWidth,nPicWidth,3, GDT_Byte, &option ); ............此处添加代码,获取数据内容 poDstDS->GetRasterBand(1)->RasterIO([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock1,xSize,ySize,GDT_Byte,0,0); poDstDS->GetRasterBand(2)->RasterIO([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock2,xSize,ySize,GDT_Byte,0,0); poDstDS->GetRasterBand(3)->RasterIO([color=#FF0000]GF_Write[/color],xTileOffset,yTileOffset,nWidth,nHeight,pafScanblock3,xSize,ySize,GDT_Byte,0,0);