crop.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

QImage * cropImage (QString filename, QPoint topLeft, QPoint bottomRight)


Function Documentation

QImage* cropImage ( QString  filename,
QPoint  topLeft,
QPoint  bottomRight 
)

Definition at line 36 of file crop.cpp.

Referenced by EditingInterface::crop().

00037 {
00038   //load original image
00039   QImage origImage( filename );
00040   
00041   //convert to 32-bit depth if necessary
00042   if( origImage.depth() < 32 ) { origImage = origImage.convertDepth( 32, Qt::AutoColor ); }
00043   
00044   //construct cropped image
00045   QImage* croppedImage = new QImage(bottomRight.x() - topLeft.x() + 1, 
00046                                     bottomRight.y() - topLeft.y() + 1,
00047                                     origImage.depth());  
00048   
00049   //iterate over each selected scanline 
00050   int xOrig, yOrig;
00051   int xCropped, yCropped;
00052   uchar *origScanLine, *croppedScanLine;
00053   
00054   for( yOrig=topLeft.y(),yCropped=0;    yOrig<=bottomRight.y();     yOrig++, yCropped++)
00055   {   
00056     //iterate over each selected pixel in scanline
00057     origScanLine    = origImage.scanLine(yOrig);
00058     croppedScanLine = croppedImage->scanLine(yCropped);
00059     
00060     for( xOrig=topLeft.x(),xCropped=0; xOrig<=bottomRight.x(); xOrig++,xCropped++)
00061     {
00062       //copy pixel color from original image to cropped image
00063       *((QRgb*)croppedScanLine+xCropped) = *((QRgb*)origScanLine+xOrig);      
00064     }
00065   }
00066   
00067   //return pointer to cropped image
00068   return croppedImage;  
00069 }


Generated on Thu Jan 3 10:52:47 2008 for AlbumShaper by  doxygen 1.5.4