QImage QTwainInterface::convertToImage(CDIB* pDib, unsigned int nWidth, unsigned int nHeight)
{	
	if (!pDib)
		return QImage( 0, 0 );

	unsigned int nUseWidth  = nWidth;
	unsigned int nUseHeight = nHeight;

	if (nUseWidth == 0)
		nUseWidth = pDib->Width();
	if (nUseHeight == 0)
		nUseHeight = pDib->Height();	

	//QPixmap pixmap(pDib->Width(), pDib->Height(), 32, QPixmap::MemoryOptim);
	//pDib->BitBlt(pixmap.handle(), 
	//	         0, 0, 
	//			 pDib->Width(), pDib->Height(),
	//			 0, 0);

	//QImage* retval = new QImage( pixmap.convertToImage().smoothScale(nUseWidth, nUseHeight) );
	QImage *image = new QImage( nUseWidth, nUseHeight, QImage::Format_RGB32 );
	pDib->BitBlt( image->getDC(), 0, 0, pDib->Width(), pDib->Height(), 0, 0);

	QImage retval = image->convertToFormat( QImage::Format_RGB32 );

	return retval;
} // !convertToImage()