mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[flutter] Added additional SkeletonDrawable.renderToXXX() methods for simple offscreen rendering.
This commit is contained in:
parent
b0c63b8fa8
commit
42186097c4
@ -67,7 +67,7 @@ class DressUpState extends State<DressUp> {
|
|||||||
? const SizedBox()
|
? const SizedBox()
|
||||||
: Row(
|
: Row(
|
||||||
children: [
|
children: [
|
||||||
Container(width: thumbnailSize, child:
|
SizedBox(width: thumbnailSize, child:
|
||||||
ListView(
|
ListView(
|
||||||
children: _skinImages.keys.map((skinName) {
|
children: _skinImages.keys.map((skinName) {
|
||||||
var rawImageData = _skinImages[skinName]!;
|
var rawImageData = _skinImages[skinName]!;
|
||||||
@ -80,7 +80,7 @@ class DressUpState extends State<DressUp> {
|
|||||||
},
|
},
|
||||||
child: _selectedSkins[skinName] == true
|
child: _selectedSkins[skinName] == true
|
||||||
? box
|
? box
|
||||||
: ColorFiltered(colorFilter: ColorFilter.mode(Colors.grey, painting.BlendMode.saturation,), child: box)
|
: ColorFiltered(colorFilter: const ColorFilter.mode(Colors.grey, painting.BlendMode.saturation,), child: box)
|
||||||
);
|
);
|
||||||
}).toList()
|
}).toList()
|
||||||
),
|
),
|
||||||
@ -97,5 +97,6 @@ class DressUpState extends State<DressUp> {
|
|||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
_drawable?.dispose();
|
_drawable?.dispose();
|
||||||
|
_customSkin?.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3308,7 +3308,7 @@ class SkeletonDrawable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<RawImageData> renderToRawImageData(double width, double height) async {
|
PictureRecorder renderToPictureRecorder(double width, double height) {
|
||||||
var bounds = skeleton.getBounds();
|
var bounds = skeleton.getBounds();
|
||||||
var scale = 1 / (bounds.width > bounds.height ? bounds.width / width : bounds.height / height);
|
var scale = 1 / (bounds.width > bounds.height ? bounds.width / width : bounds.height / height);
|
||||||
|
|
||||||
@ -3324,6 +3324,17 @@ class SkeletonDrawable {
|
|||||||
canvas.translate(-(bounds.x + bounds.width / 2), -(bounds.y + bounds.height / 2));
|
canvas.translate(-(bounds.x + bounds.width / 2), -(bounds.y + bounds.height / 2));
|
||||||
canvas.drawRect(const Rect.fromLTRB(-5, -5, 5, -5), paint..color = material.Colors.red);
|
canvas.drawRect(const Rect.fromLTRB(-5, -5, 5, -5), paint..color = material.Colors.red);
|
||||||
renderToCanvas(canvas);
|
renderToCanvas(canvas);
|
||||||
|
return recorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Uint8List> renderToPng(double width, double height) async {
|
||||||
|
final recorder = renderToPictureRecorder(width, height);
|
||||||
|
final image = await recorder.endRecording().toImage(width.toInt(), height.toInt());
|
||||||
|
return (await image.toByteData(format: ImageByteFormat.png))!.buffer.asUint8List();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<RawImageData> renderToRawImageData(double width, double height) async {
|
||||||
|
final recorder = renderToPictureRecorder(width, height);
|
||||||
var rawImageData = (await (await recorder.endRecording().toImage(width.toInt(), height.toInt())).toByteData(format: ImageByteFormat.rawRgba))!.buffer.asUint8List();
|
var rawImageData = (await (await recorder.endRecording().toImage(width.toInt(), height.toInt())).toByteData(format: ImageByteFormat.rawRgba))!.buffer.asUint8List();
|
||||||
return RawImageData(rawImageData, width.toInt(), height.toInt());
|
return RawImageData(rawImageData, width.toInt(), height.toInt());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user