PDA

View Full Version : a runtime errors in QPainter::DrawPixmap(..)



richardander
12th February 2009, 08:53
Hello,

My application display a qpixmap object, inputpixmap, with the following code working well:




QPainter painter( &m_pixmap ); // m_pixmap is a QPixmap object with size finalWidth, finalHeight;
painter.setWindow( 0, 0, imageW, imageH );
painter.drawPixmap( 0, 0, inputPixmap );




However, if the finalWidth and finalHeight are much bigger than image size (imageW and imageH), the QT build-in scale function shows poor interpolation image. So I am trying to use my own function to interpolate the data to the finalWidth/finalHeight and display. Following is my code:




QPainter painter( &m_Pixmap );

QImage orgImg = inputPixmap.toImage();
unsigned short * orgImgData = (unsigned short *) orgImg.bits();
unsigned short * newImageData = new unsigned short [ finalWidth * finalHeight * sizeof( unsigned short ) ];
if( !newImageData )
{
delete [] orgImgData;
return;
}


BilinearInterpolate(
orgImgData,
imageW,
imageH,
newImageData,
finalWidth,
finalHeight,
0,
0,
imageW,
imageH );


QImage displayImage( (uchar * )newImageData, finalWidth, finalHeight, QImage::Format_Indexed8);

// painter.setWindow( 0, 0, finalWidth, finalHeight );
painter.drawImage( 0, 0, displayImage);




I ran it in debug mode. at line "painter.drawImage( 0, 0, displayImage);", I got following error:

"Debug Error!,

Program: testApp.exe
Module: 4.4.3
File: global\qglobal.cpp
Line: 2090

ASSERT failure in QVector<T>::at:"index out of range", file c:\iwamake\build_vs2003_evalutin___padding___\incl ude\qtcore\../../src/corelib/tols/qvector.h, line 317 "

Could anyone tell me what is the problem and how to fix it?

BTW, if I don't comment code " painter.setWindow( 0, 0, finalWidth, finalHeight );", the program will pop up the same error message at this line. Do I need this line?


thank you very much!

richardander
12th February 2009, 18:46
Can anyone help find out the problem?

thank you!