changeImage method
Swap the image used to draw the mesh for this image node. Returns true when successful.
Implementation
bool changeImage(ui.Image image) {
if (triangles == null || dynamicUV == null) {
return false;
}
_uvBuffer = makeVertexUVBuffer();
int count = vertexCount;
// SKIA requires texture coordinates in full image space, not traditional
// normalized uv coordinates.
var duv = dynamicUV!;
int idx = 0;
for (int i = 0; i < count; i++) {
_uvBuffer[idx] = duv[idx] * image.width;
_uvBuffer[idx + 1] = duv[idx + 1] * image.height;
idx += 2;
}
_paint.shader = ui.ImageShader(
image, ui.TileMode.clamp, ui.TileMode.clamp, _identityMatrix);
_canvasVertices = ui.Vertices.raw(ui.VertexMode.triangles, _vertexBuffer,
indices: _indices, textureCoordinates: _uvBuffer);
onPaintUpdated(_paint);
return true;
}