[kde-edu]: A briefly introduction of myself

Torsten Rahn torsten.rahn at credativ.de
Fri Jun 1 07:06:44 CEST 2007


> scuse me, can you tell me why the line:
> "m_scanLine = (QRgb*)( canvasImage->scanLine( m_y ) ) + xLeft;"
> converts a line into a color?

:-) Sure. Have a look at 

http://doc.trolltech.com/4.2/qimage.html#scanLine

From the current line m_y and line position xLeft of the pixel we calculate 
the pointer that points to the color value at the scanline position in the 
canvasImage. As written in the docs above:

 "If you are accessing 32-bpp image data, cast the returned pointer to QRgb* 
(QRgb has a 32-bit size) and use it to read/write the pixel value." 

So that's why we cast the scanLine result (that returns the color value at 
position (xLeft, m_y) ) to (QRgb*). 

That's the whole explanation. Or look at it this way:

So what "QImage::scanLine(int row)" returns is actually not the scanLine 
itself but a pointer to the contents of the first entry of the scanline in 
the row "row". As we add "xLeft" to the pointer address we are able to 
retrieve the contents at an arbitrary position in that line. The contents is 
of course the color specified as RGB.

Has it become clearer? 

Torsten

-- 
 Torsten Rahn

 Tel.: 0 21 61 - 46 43 - 192

credativ GmbH, HRB Mönchengladbach 12080
Hohenzollernstr. 133, 41061 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz


More information about the kde-edu mailing list