CanvasView. Image

Before drawing an image, it must first be loaded. The global function is used for this:

func LoadImage(url string, onLoaded func(Image), session Session) Image {

The image is loaded asynchronously. After the download is finished, the function passed in the second argument will be called.If the image was loaded successfully, then the LoadingStatus() function of the Image interface willreturn the value ImageReady (1), if an error occurred while loading, then this function will return ImageLoadingError (2).The textual description of the error is returned by the LoadingError() function

Unlike an ImageView, loading an Image does not take into account the pixel density.It is up to you to decide which image to upload. You can do it like this:

var url string
if session.PixelRatio() == 2 {
	url = "image@2x.png"
} else {
	url = "image.png"
}

The following functions are used to draw the image:

DrawImage(x, y float64, image Image)
DrawImageInRect(x, y, width, height float64, image Image)
DrawImageFragment(srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight float64, image Image)

The DrawImage function displays the image as it is (without scaling): x, y - coordinates of the upper left corner of the image

The DrawImageInRect function displays the image with scaling: x, y are coordinates of the upper left corner of the image,width, height are width and height of the result

The DrawImageFragment function displays a fragment of the image with scaling: srcX, srcY, srcWidth, srcHeight describethe original area of the image, dstX, dstY, dstWidth, dstHeight describe the resulting area.

Image can also be used in fill style

SetImageFillStyle(image Image, repeat int)

where repeat can take on the following values:

Value Constant Description
0 NoRepeat Image is not repeated
1 RepeatXY Image is repeated vertically and horizontally
2 RepeatX The image is repeated horizontally only
3 RepeatY The image is repeated vertically only