Translations: 简体中文
The ZoomImage library includes several components to choose from, so you can choose the right one for your needs.
Compose multiplatform:
- SketchZoomAsyncImage:Integrated Sketch image loading library, support network images and
subsampling. Example: SketchZoomAsyncImageSample.
Recommended
- CoilZoomAsyncImage:Integrated Coil image loading library, support network images and subsampling. Example: CoilZoomAsyncImageSample
- ZoomImage:The basic zoom component does not integrate the image loading library and does not
support network images. You need to call
subsampling.setImageResource()
method to support subsampling. Example: ZoomImageSample
Only android compose:
- GlideZoomAsyncImage:Integrated Glide image loading library, support network images and subsampling. Example: GlideZoomAsyncImageSample
Android view:
- SketchZoomImageView:Integrated Sketch
image loading library, support network images and subsampling.
Example: SketchZoomImageViewFragment.
Recommended
- CoilZoomImageView:Integrated Coil image loading library, support network images and subsampling. Example: CoilZoomImageViewFragment
- GlideZoomImageView:Integrated Glide image loading library, support network images and subsampling. Example: GlideZoomImageViewFragment
- PicassoZoomImageView:Integrated Picasso image loading library, support network images and subsampling. Example: PicassoZoomImageViewFragment
- ZoomImageView
:The basic zoom component does not integrate the image loading library and does not support
network images. You need to call
subsampling.setImageResource()
method to support subsampling. Example: ZoomImageViewFragment
Tip
- Different components need to import different dependencies, please refer to README to import the corresponding dependencies*
- Components with integrated image loaders can support image and subsampling from any source without any additional work
- Components that do not integrate an image loader can only display local images and require an
additional call to the
setSubsamplingImage()
method to support subsampling functionality
Compose multiplatform:
// Using the basic ZoomImage component
val zoomState: ZoomState by rememberZoomState()
LaunchedEffect(zoomState.subsampling) {
val resUri = Res.getUri("files/huge_world.jpeg")
val imageSource = ImageSource.fromComposeResource(resUri)
zoomState.setSubsamplingImage(imageSource)
}
ZoomImage(
painter = painterResource(Res.drawable.huge_world_thumbnail),
contentDescription = "view image",
modifier = Modifier.fillMaxSize(),
zoomState = zoomState,
)
// Using the SketchZoomAsyncImage component
SketchZoomAsyncImage(
uri = "https://sample.com/sample.jpeg",
contentDescription = "view image",
modifier = Modifier.fillMaxSize(),
)
// Using the CoilZoomAsyncImage component
CoilZoomAsyncImage(
model = "https://sample.com/sample.jpeg",
contentDescription = "view image",
modifier = Modifier.fillMaxSize(),
)
Only android compose:
// Using the GlideZoomAsyncImage component
GlideZoomAsyncImage(
model = "https://sample.com/sample.jpeg",
contentDescription = "view image",
modifier = Modifier.fillMaxSize(),
)
Android view:
// Using the basic ZoomImageImage component
val zoomImageView = ZoomImageView(context)
zoomImageView.setImageResource(R.drawable.huge_world_thumbnail)
val imageSource = ImageSource.fromResource(context, R.raw.huge_world)
zoomImageView.setSubsamplingImage(imageSource)
// Using the SketchZoomImageView component
val sketchZoomImageView = SketchZoomImageView(context)
sketchZoomImageView.loadImage("https://sample.com/sample.jpeg")
// Using the CoilZoomImageView component
val coilZoomImageView = CoilZoomImageView(context)
coilZoomImageView.load("https://sample.com/sample.jpeg")
// Using the GlideZoomImageView component
val glideZoomImageView = GlideZoomImageView(context)
Glide.with(this@GlideZoomImageViewFragment)
.load("https://sample.com/sample.jpeg")
.into(glideZoomImageView)
// Using the PicassoZoomImageView component
val picassoZoomImageView = PicassoZoomImageView(context)
picassoZoomImageViewImage.loadImage("https://sample.com/sample.jpeg")
Tip
- PicassoZoomImageView provides a set of specialized APIs to listen for load results and get URIs, to support subsampling, so please don't load images directly using the official API
- For more usage methods related to image loading of each component, please refer to the usage of its original component.
The scaling and subsampling APIs are encapsulated in different classes. You can directly control scaling and subsampling or obtain related information through them, as follows:
- compose versions are ZoomableState and SubsamplingState
- view versions are ZoomableEngine and SubsamplingEngine
example:
// compose
val zoomState: ZoomState by rememberZoomState()
SketchZoomAsyncImage(
imageUri = "https://sample.com/sample.jpeg",
contentDescription = "view image",
modifier = Modifier.fillMaxSize(),
zoomState = zoomState,
)
val zoomable: ZoomableState = zoomState.zoomable
val subsampling: SubsamplingState = zoomState.subsampling
// view
val sketchZoomImageView = SketchZoomImageView(context)
val zoomable: ZoomableEngine = sketchZoomImageView.zoomable
val subsampling: SubsamplingEngine = sketchZoomImageView.subsampling
[!TIP] Note: The relevant properties of the view version are wrapped in StateFlow, so its name is suffixed with State compared to the compose version
zoomable.baseTransform: Transform
: Base transformation, include the base scale, offset, rotation, which is affected by contentScale, alignment properties and rotate methodzoomable.userTransform: Transform
: User transformation, include the user scale, offset, rotation, which is affected by the user's gesture, readMode properties and scale, offset, locate methodzoomable.transform: Transform
: Final transformation, include the final scale, offset, rotation, is equivalent tobaseTransform + userTransform
zoomable.minScale: Float
: Minimum scale factor, for limits the final scale factor, and as a target value for one of when switch scalezoomable.mediumScale: Float
: Medium scale factor, only as a target value for one of when switch scalezoomable.maxScale: Float
: Maximum scale factor, for limits the final scale factor, and as a target value for one of when switch scalezoomable.continuousTransformType: Int
: If true, a transformation is currently in progress, possibly in a continuous gesture operation, or an animation is in progresszoomable.contentBaseDisplayRect: IntRect
: The content region in the container after the baseTransform transformationzoomable.contentBaseVisibleRect: IntRect
: The content is visible region to the user after the baseTransform transformationzoomable.contentDisplayRect: IntRect
: The content region in the container after the final transform transformationzoomable.contentVisibleRect: IntRect
: The content is visible region to the user after the final transform transformationzoomable.scrollEdge: ScrollEdge
: Edge state for the current offsetzoomable.containerSize: IntSize
: The size of the container that holds the contentzoomable.contentSize: IntSize
: The size of the content, usually Painter.intrinsicSize.round()zoomable.contentOriginSize: IntSize
: The original size of the contentsubsampling.ready: Boolean
: Whether the image is ready for subsamplingsubsampling.imageInfo: ImageInfo
: The information of the image, including width, height, format, exif information, etcsubsampling.exifOrientation: ExifOrientation
: The exif information of the imagesubsampling.foregroundTiles: List<TileSnapshot>
: List of current foreground tilessubsampling.backgroundTiles: List<TileSnapshot>
: List of current background tilessubsampling.sampleSize: Int
: The sample size of the imagesubsampling.imageLoadRect: IntRect
: The image load rectsubsampling.tileGridSizeMap: Map<Int, IntOffset>
: Tile grid size map
- The relevant properties of the compose version are wrapped in State and can be read directly in the Composable function to implement listening
- The relevant properties of the view are wrapped in StateFlow, and its collect function can be called to implement the listening
Tip
For more detailed information about scale, offset, rotation, subsampling, read mode, scroll bar and other functions, please refer to the documentation at the end of the page*
- Scale: Scale the image to see clearer details
- Offset: Move the image to see content outside the container
- Rotate: Rotate the image to view content from different angles
- Locate: Locate anywhere in the image
- Read Mode: Long images initially fill the screen for easy reading
- Click: Receive click events
- Subsampling: Display large images through subsampling to avoid OOM
- Scroll Bar: Displays horizontal and vertical scroll bars
- Log: Modify log level and output pipeline
- Modifier.zoom()