Declaration (see MWindow.h):
void drawImage(const MImage& img, const MRect& rect, double angle = 0.0, const MPoint& rotCen = AutoPoint, bool highQuality = false);
Draws a raster image in the window.
The image to draw.
Details: If img is empty, nothing is drawn, of course.
Size and position for the drawn image (the img will be fitted to rect).
Details: If rect.p1() is an invalid MPoint, then nothing is drawn.
If rect.size() is an invalid MSize, then width and height of img are used to validate the invalid components of rect.
The validated rect is rounded out to a nearest integral rect (fitting an image to non-integral size makes little sense), and transformed according to the latest setDrawTransform.
Afterward, the rect is rotated according to angle and rotCen parameters (see below).
If, after all these transformations, rect becomes invalid or its w or h components become non-positive (less than 1E-9 to be exact), then nothing is drawn. Otherwise, the resulting rect is used as the frame for the drawn image, i.e. the image is fitted to this transformed rect using a pixel interpolating algorithm if necessary. The interpolation algorithm depends on the HighQuality property - for high quality a more sophisticated (but less efficient) algorithm is used to fit the image to rect. See stretch parameter below for more details.
- The z and d components are reserved for the future support of 3D drawing
If true, then img is stretched to fill the entire rect, otherwise just its width or height.
Details: In other words, if stretch is false, then the aspect ratio of img is preserved, and if stretch is true then the image may be distorted (unless, of course, rect has the same aspect ratio as img). The aspect ratio is the width of the image divided by its height.
In any case, the image is made as large as possible within the specified constraints, i.e. either its width or its height (or both) is equal to that of the transformed rect. If stretch is false, then the image is centered within rect.
As mentioned in rect Details, the image is interpolated to fit the transformed rect. Stretching uses the same algorithm, i.e. bi-linear interpolation if HighQuality is false, and bi-cubic interpolation if HighQuality is true. The bi-cubic algorithm prevents certain scaling artifacts, but works noticeably slower. Of course, if scaling is not required (width and height of rect are equal to the image's width and height), then the HighQuality property and the stretch parameter are irrelevant.
Rotate img by angle degrees counter-clockwise around rotCen.
The center point around which the image is rotated (ignored if angle is 0).
Details: If rotCen is an invalid MPoint, then the image is rotated around the center point of the transformed rect. Otherwise, rotCen is transformed according to the latest setDrawTransform and used as a rotation center.
- If rotation is not required (angle is 0), drawImage works significantly faster, so use the rotation carefully, especially for large images
- The z component is reserved for the future support of 3D drawing
Let us know
Please Contact us to report any errors on this page, or to suggest any improvements.