Hello,

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

Qt Code:
  1. QPainter painter( &m_pixmap ); // m_pixmap is a QPixmap object with size finalWidth, finalHeight;
  2. painter.setWindow( 0, 0, imageW, imageH );
  3. painter.drawPixmap( 0, 0, inputPixmap );
To copy to clipboard, switch view to plain text mode 


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:

Qt Code:
  1. QPainter painter( &m_Pixmap );
  2.  
  3. QImage orgImg = inputPixmap.toImage();
  4. unsigned short * orgImgData = (unsigned short *) orgImg.bits();
  5. unsigned short * newImageData = new unsigned short [ finalWidth * finalHeight * sizeof( unsigned short ) ];
  6. if( !newImageData )
  7. {
  8. delete [] orgImgData;
  9. return;
  10. }
  11.  
  12.  
  13. BilinearInterpolate(
  14. orgImgData,
  15. imageW,
  16. imageH,
  17. newImageData,
  18. finalWidth,
  19. finalHeight,
  20. 0,
  21. 0,
  22. imageW,
  23. imageH );
  24.  
  25.  
  26. QImage displayImage( (uchar * )newImageData, finalWidth, finalHeight, QImage::Format_Indexed8);
  27.  
  28. // painter.setWindow( 0, 0, finalWidth, finalHeight );
  29. painter.drawImage( 0, 0, displayImage);
To copy to clipboard, switch view to plain text mode 

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!