[ios] Add boundsProvider to renderToImage (#3002)

This commit is contained in:
Mario Zechner 2026-02-27 12:35:07 +01:00
parent a558c44ef4
commit 29eb398c05
4 changed files with 13 additions and 3 deletions

View File

@ -22,3 +22,4 @@
- Add option to disable drawing when out of viewport (#18)
- Add docs for public Spine classes/methods (#19)
- Fix various regressions (#20)
- Add `boundsProvider` parameter to `SkeletonDrawableWrapper.renderToImage(...)` to align image rendering bounds with `SpineView` (#3002)

View File

@ -58,7 +58,7 @@ struct DressUp: View {
SpineView(
from: .drawable(drawable),
controller: model.controller,
boundsProvider: SkinAndAnimationBounds(skins: ["full-skins/girl"])
boundsProvider: model.boundsProvider
)
} else {
Spacer()
@ -76,6 +76,7 @@ struct DressUp: View {
final class DressUpModel: ObservableObject {
let thumbnailSize = CGSize(width: 200, height: 200)
let boundsProvider: BoundsProvider = SkinAndAnimationBounds(skins: ["full-skins/girl"])
@Published
var controller: SpineController
@ -116,6 +117,7 @@ final class DressUpModel: ObservableObject {
let skinName = skin.name
self.skinImages[skinName] = try drawable.renderToImage(
size: self.thumbnailSize,
boundsProvider: self.boundsProvider,
backgroundColor: .white,
scaleFactor: UIScreen.main.scale
)

View File

@ -39,11 +39,18 @@ import Foundation
///
/// Parameters:
/// - size: The size of the `CGImage` that should be rendered.
/// - boundsProvider: The skeleton bounds provider used to compute fitting and positioning.
/// - backgroundColor: the background color of the image
/// - scaleFactor: The scale factor. Set this to `UIScreen.main.scale` if you want to show the image in a view
public func renderToImage(size: CGSize, backgroundColor: UIColor, scaleFactor: CGFloat = 1) throws -> CGImage? {
public func renderToImage(
size: CGSize,
boundsProvider: BoundsProvider = SetupPoseBounds(),
backgroundColor: UIColor,
scaleFactor: CGFloat = 1
) throws -> CGImage? {
let spineView = SpineUIView(
controller: SpineController(disposeDrawableOnDeInit: false), // Doesn't own the drawable
boundsProvider: boundsProvider,
backgroundColor: backgroundColor
)
spineView.frame = CGRect(origin: .zero, size: size)

View File

@ -45,7 +45,7 @@ import UIKit
/// To update the ``AnimationState`` and apply it to the ``Skeleton`` call the ``AnimationStateWrapper/update`` function, providing it
/// a delta time in seconds to advance the animations.
///
/// To render the current pose of the ``Skeleton`` as a `CGImage`, use ``SkeletonDrawableWrapper/renderToImage(size:backgroundColor:scaleFactor:)``.
/// To render the current pose of the ``Skeleton`` as a `CGImage`, use ``SkeletonDrawableWrapper/renderToImage(size:boundsProvider:backgroundColor:scaleFactor:)``.
///
/// When the skeleton drawable is no longer needed, call the ``SkeletonDrawableWrapper/dispose()`` method to release its resources. If
/// the skeleton drawable was constructed from a shared ``Atlas`` and ``SkeletonData``, make sure to dispose the