Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-31540

Printing adjecent images with alpha to pdf causes image edge overlap

    XMLWordPrintable

Details

    • 624740cdcdd4abfb15bbbc8a8aa056c57712499f

    Description

      Run the following code. As a result, "kjg.pdf" and "kjg.png" is created using the same image. Pdf, which is created using QPrinter, does NOT look correct. Png, which uses QImage::save(), looks correct.

      #include <QApplication>
      #include <QPrinter>
      #include <QPainter>
      #include <QImage>
      #include <QString>
      
      int main( int argc, char **argv )
      {
          QApplication app( argc, argv );
      
          double dpi = 300.0;
      
          // Setup 8.5 x 11 inch printer
          //-------------------------------
          QPrinter *printer = new QPrinter( QPrinter::HighResolution );
          printer->setOutputFormat( QPrinter::PdfFormat );
          printer->setFullPage( true );
          printer->setOutputFileName( "kjg.pdf" );
          printer->setColorMode( QPrinter::Color );
          printer->setOrientation( QPrinter::Portrait );
          printer->setPaperSize( QSizeF( 8.5, 11 ), QPrinter::Inch );
          printer->setResolution( (int) dpi );
      
      
          // Setup 8.5 x 11 @ 300 dpi raster image.
          //-----------------------------------------
          QImage *outImg = new QImage( 2550, 3300, QImage::Format_ARGB32 );
      
          // Create out painters
          //----------------------
          QList<QPainter *> painters;
          painters.append( new QPainter( printer ) );
          painters.append( new QPainter( outImg ) );
      
          // Image to draw.
          //----------------
          int w = 100;
          int h = 1000;
          QImage *img = new QImage( w, h, QImage::Format_ARGB32 );
          img->fill( qRgba( 255, 0, 0, 128 ) );
      
          for( int j = 0; j < 2; j++ )
          {
              if( ! painters[j]->isActive() )
              {
                  qDebug( "Painter not active." );
                  delete outImg;
                  delete printer;
                  return( 0 );
              }
      
              painters[j]->setRenderHint( QPainter::Antialiasing );
      
              int x = 10;
              int y = 100;
              int prevX;
      
              for( int i = 0; i < 10; i++ )
              {
                  if( i != 0 )
                  {
                      x = prevX + w;
                      // Play with this value to see the different behavior.
      //                x += 1;
                  }
      
                  prevX = x;
                  painters[j]->drawImage( x, y, *img );
              }
      
              painters[j]->end();
          }
      
          outImg->save( "kjg.png", "PNG" );
      
          delete img;
          delete outImg;
          delete printer;
      
          return( 0 );
      }
      

      Attachments

        1. kjg.pdf
          4 kB
        2. kjg.png
          kjg.png
          34 kB
        3. printed_to_pdf.jpg
          printed_to_pdf.jpg
          15 kB
        4. qtbug31540.tar
          10 kB

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sletta Gunnar Sletta
              qtcomsupport Qt Support
              Votes:
              5 Vote for this issue
              Watchers:
              14 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes