Texture.fromImage constructor
- GpuContext gpuContext,
- Image image
Wraps the GPU texture that backs image as a Flutter GPU Texture,
without copying any pixel data.
The returned texture shares its storage with image, so it stays valid
for as long as either the returned texture or image is alive. It is
intended for sampling (for example as a material texture) and reflects
the usage of the underlying texture, so it is not guaranteed to be usable
as a render pass attachment.
image must be backed by a GPU texture. Use an image produced by the
asynchronous RepaintBoundary.toImage (or Picture.toImage). An image
from toImageSync rasterizes asynchronously and may not have a texture
yet when this is called. Throws if image has no compatible texture.
Implementation
factory Texture.fromImage(GpuContext gpuContext, ui.Image image) {
final Int32List info = _imageTextureInfo(gpuContext, image);
if (info.length != 10) {
throw Exception(
'Texture.fromImage could not wrap the image because it is not backed '
'by a compatible GPU texture. Use an image from the asynchronous '
'RepaintBoundary.toImage rather than toImageSync.',
);
}
return Texture._fromImage(gpuContext, image, info);
}