| DrawImage | ||
| Contents | ||||||
|
||||||
DrawImage is a new set of methods for the existing Draw class. These methods leverage the open source FreeImage library and integrate it with Draw. This provides the ability to load and save additional formats such as JPEG, PNG, TIFF and so on, as well as providing the ability to rotate, scale, shear and otherwise manipulate images. In addition there are a number of new Draw methods that enhance this functionality by providing features not found in FreeImage, such as colour control, conversion to grayscale, automatic image resizing, image tiling and clipping and so on.
Please note that this documentation is under construction and is being expanded.
Using DrawImage is as simple as ticking the Enable DrawImage tickbox on the global extension
| DrawImage Methods in the Draw class | |||
| Draw.diReadImage | Load an image from disk, resource or BLOB into the control | ||
![]()
Click on the
(up)
icon to go back to the layer Method Index.
diReadImage
(string fName, long x, long y, long w=0, long h=0, long tileFlag=0, long
maxVertTiles=0, long maxHorizTiles=0, real fAngle=0, long indexColor=-1, <*blob
imageBlob>)
Loads a large variety of image formats, and supports loading from disk (file), resource (compiled into the application) or BLOB. Supports BMP, PNG, JPEG, TIFF and more. This method also supports resizing (scaling), rotating and tiling of the image, as well as placing the image treating a specified colour as transparent.
Parameters
fName
The name of the file to load. If the imageBlob parameter is passed this can
be an empty string (it will be ignored).
x
The x (horizontal) coordinate to place the image at. The number of pixels
from the left hand side of the Draw control.
y
The y (vertical) coordinate to place the image at. The number of pixels
from the top of the Draw control.
w [optional]
The width of the image, pass this as 0 in order to use the actual width of
the image. If a width is specified the image will be scaled to that width.
Use the BestFit() method to calculate proportional resizing to maintain the
aspect ratio while resizing the image to fit within a desired area.
Note: If tiling is used then this is the area to be tiled over using the image.
h [optional]
The height height of the image, pass this as 0 in order to use the actual
height of the image. If a height is specified the image will be scaled to
that height. Use the BestFit() method to calculate proportional resizing to
maintain the aspect ratio while resizing the image to fit within a desired
area.
Note: If tiling is used then this is the area to be tiled over using the image.
tileFlag [optional]
Flag for setting the tiling options. Valid values are 0 (zero) for no
tiling; Draw:Tile (using tiling);
Draw:TileHoriz (horizontal tiling only); or
Draw:TileVert (vertical tiling only).
tilesVert [optional]
Limits the number of times the image can be tiled vertically. Otherwise the
image is tiled as many times as needed over the specified area, and clipped
to fit.
tilesHoriz [optional]
Limits the number of times the image can be tiled horizontally. Otherwise
the image is tiled as many times as needed over the specified area, and
clipped to fit.
Return Values
None. If the method fails it calls ErrorTrap() with an error description.
Remarks
Draw supports a number of methods for handling images in various manners. See the diReadImageToBuffer() method, which performns the same basic function, however it reads the image into a buffer which can then be written to the Draw control by calling diImageFromBuffer() at any time. This supports the same functionality, but allows the image to be stored and reused without loading it from disk, which provides dramatically improved performance when using the same image a number of times (this is the approach used internally to handle tiling).
Examples
if not Drawer.useDrawImage
Drawer.InitDrawImage()
end
Drawer.Blank(color:white)
i = Random(1, 13)
Drawer.diGetImageInfo(i & '.jpg', imageWidth, imageHeight, imageBitDepth, imageType)
!--- Calculate the best fit within the control, while maintaining the aspect ratio of the image
! BestFit(ulong srcW, ulong srcH, ulong maxW, ulong maxH, *ulong newW, *ulong newH)
drawer.BestFit(imageWidth, imageHeight, drawer.width, drawer.height, imageWidth, imageHeight)
!--- display the image centered on the canvas
! diReadImage(string fName, long x, long y, long w=0, long h=0, long tileFlag=0, |
! long maxVertTiles=0, long maxHorizTiles=0, <*blob imageBlob>)
drawer.diReadImage(i & '.jpg', 1 + (drawer.width-imageWidth)/2, |
1 + (drawer.height-imageHeight)/2, imageWidth, imageHeight)
drawer.Display()
See Also
InitDrawImage, BestFit, diReadImageToBuffer, diImageFromBuffer, diGetImageInfo
These are the Draw class properties that are useful when using DrawImage methods. You can access all these properties directly (they are not private and so you don't need accessor method). Properties that should be used with caution are indicated by an underscore preceding the name. Typically these properties should not be accessed directly.
| DrawPaint Properties | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The canvas (background) color for the control.