Forums › TWAIN Classic › Memory transfer mode: desuming the header › Reply To: Memory transfer mode: desuming the header
August 12, 2009 at 2:41 pm
#24991
Now, i can get the image data by a memory transfer, desume the hneeded headers (BITMAPFLILEHEADER and BITMAPINFOHEADER),
and i can save it into the filesystem, but when i open the image with a program (gimp for example) i note that the image is flipped vertically.
Why???
Anyone can say me why the source transfer image data in that way?
Post my code in relevants parts:
void doBufferedMemoryTransfer()
{
/*commented code, only explained for semplicity*/
//call DG_CONTROL,DAT_SETUPMEMXFER,MSG_GET so i can setup twMemXFer that is of TW_SETUPMEMXFER type
// call getImageInfo(); and getImageLayout(); that wraps DG_IMAGE,DAT_IMAGEINFO,MSG_GET and DG_IMAGE,DAT_IMAGELAYOUT,MSG_GET respectively
// in a loop i call DG_IMAGE,DAT_IMAGEMEMXFER,MSG_GET until TWRC_XFERDONE is fired by last call to DG_IMAGE,DAT_IMAGEMEMXFER,MSG_GET
/*end commented code*/
...
case TWRC_SUCCESS:
fwrite((void*)buf,1,(UINT)twImageMemXFer.BytesWritten,pFile);
break;
case TWRC_XFERDONE:
//write last buffer into the file
fwrite((void*)buf,1,(UINT)twImageMemXFer.BytesWritten,pFile);
//call fseek to move the file pointer to begin of file in order to write
//image headers that needs to be placed in
fseek ( pFile , 0 , SEEK_SET );
bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER) ;
bitmapFileHeader.bfType = 0x4D42;//BM
bitmapFileHeader.bfReserved1 = 0;
bitmapFileHeader.bfReserved2 = 0;
bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) ;
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER) ;
bitmapInfoHeader.biPlanes = 1;
bitmapInfoHeader.biBitCount = imageInfo->getBitsPerPixel();
bitmapInfoHeader.biCompression = BI_RGB;//imageInfo->getCompression();
bitmapInfoHeader.biSizeImage = ((((imageInfo->getImageWidth() * imageInfo->getBitsPerPixel() + 31) / 32)*4) * abs(imageInfo->getImageLength()));
bitmapInfoHeader.biXPelsPerMeter = 0;
bitmapInfoHeader.biYPelsPerMeter = 0;
bitmapInfoHeader.biClrUsed = 0;
bitmapInfoHeader.biClrImportant = 0;
bitmapInfoHeader.biWidth = imageInfo->getImageWidth();
bitmapInfoHeader.biHeight = imageInfo->getImageLength();
fwrite(&bitmapFileHeader, 1, sizeof(BITMAPFILEHEADER), pFile);
fwrite(&bitmapInfoHeader, 1, sizeof(BITMAPINFOHEADER), pFile);
//other calls to free memory, close file handle and exit from the loop omitted.
break;
}
The imageInfo instance is a instance of a class that wraps TW_IMAGEINFO struct.
best regards