ich habe ein gekacheltes Bild, dass ich Kachel für Kachel einlesen und im Anschluss unter Verwendung von QImage (oder QPixmap) anzeigen möchte. Ich lese die Bildblöcke / Kacheln einzeln in einen Char-Buffer ein und hänge diese anschließend an ein QByteArray ab. Nach dem Einlesen aller Kachlen benutze ich das QByteArray als Eingabepuffer für die QImage Parameterliste.
Ich erhalte jedoch im Ergebis immer nur eine Kachel, die allerdings mehrmals angezeigt wird. Gibt es ein Möglichkeit, wie ich das zusammenhängende Feld übergeben bzw. irgendwie anzeigen kann?
Code: Alles auswählen
bool MdiChild::openImage(const QString &fileName)
{
char character = ' ';;
char fName[1024];
GDALDataset *poDataset = NULL; // GDAL dataset which holds all rasterbands of one image + additional metadata
GDALRasterBand *poBand = NULL; // GDAL raster band which contains all pixels + additional metadata of one band
GDALRasterBand *ovBand = NULL;
GDALDataType type; //GDAL data type which describes the pixel storage format / data type
char *block = NULL; // buffer for storing read image data
int nXBlockSize = 0, nYBlockSize = 0, n = 0;
int nXBlocks = 0, nYBlocks = 0;
int iXBlock = 0, iYBlock = 0;
for (int i = 0; i < 1024; i++)
fName[i] = '\0';
for (int i = 0; i < fileName.size(); i++) // conversion of selected image file path form QString into unsigned char
{
character = fileName.at(i).toAscii();
fName[i] = character;
}
const char* pszFilename = fName;
GDALAllRegister(); // register all GDAL image drivers
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly ); // open dataset, modus: read only
if( poDataset == NULL )
{
QMessageBox::warning(this, tr("I-MET"),
tr("Reading of file %1 failed.")
.arg(fileName));
GDALDestroyDriverManager();
return false;
}
poBand = poDataset->GetRasterBand(1); // retrieve one rasterband from the dataset
poBand->GetBlockSize( &nXBlockSize, &nYBlockSize ); // calculation of tile / block size
nXBlocks = (poBand->GetXSize() + nXBlockSize - 1) / nXBlockSize;
nYBlocks = (poBand->GetYSize() + nYBlockSize - 1) / nYBlockSize;
type = poBand->GetRasterDataType(); // determination of pixel data type
n = poBand->GetOverviewCount(); // retrieval of number of image pyramide levels
ovBand = poBand->GetOverview(n-1); // access of one pyramide level
int nXSize = poBand->GetXSize(); // retrieval of image width [pixel]
int nYSize = poBand->GetYSize(); // retrieval of image height [pixel]
block = (char *) CPLMalloc(sizeof(type) * nXBlockSize * BlockSize);
for (int i = 0; i < 10; i++)
{
for ( int j = 0; j < 10; j++)
{
poBand->ReadBlock(i, j, block);
imgArray.append(block);
}
}
ptrCh = (unsigned char*) imgArray.data();
QImage img(ptrCh, nXBlockSize, nYBlockSize ,QImage::Format_RGB32); // create QImage using read image data
image = img;
GDALClose(poDataset); // close data set
setCurrentFile(fileName); // set current file name as image window title
return true;
}