Skip to content

Commit a622173

Browse files
- fix: record screen on Iphone
1 parent 67d5953 commit a622173

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/src/exporter.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class Exporter {
3030
}
3131
final bytesImages = <RawFrame>[];
3232
for (final frame in _frames) {
33-
final bytesImage =
34-
await frame.image.toByteData(format: ui.ImageByteFormat.png);
33+
final bytesImage = await frame.image.toByteData(format: ui.ImageByteFormat.png);
3534

3635
if (frame.image.width >= _maxWidthFrame) {
3736
_maxWidthFrame = frame.image.width;
@@ -55,8 +54,7 @@ class Exporter {
5554
if (frames == null) {
5655
return null;
5756
}
58-
return compute(
59-
_exportGif, DataHolder(frames, _maxWidthFrame, _maxHeightFrame));
57+
return compute(_exportGif, DataHolder(frames, _maxWidthFrame, _maxHeightFrame));
6058
}
6159

6260
static Future<List<int>?> _exportGif(DataHolder data) async {
@@ -98,15 +96,20 @@ class Exporter {
9896
static image.PaletteUint8 _convertPalette(image.Palette palette) {
9997
final newPalette = image.PaletteUint8(palette.numColors, 4);
10098
for (var i = 0; i < palette.numColors; i++) {
101-
newPalette.setRgba(
102-
i, palette.getRed(i), palette.getGreen(i), palette.getBlue(i), 255);
99+
newPalette.setRgba(i, palette.getRed(i), palette.getGreen(i), palette.getBlue(i), 255);
103100
}
104101
return newPalette;
105102
}
106103

107-
static image.Image _encodeGifWIthTransparency(image.Image srcImage,
108-
{int transparencyThreshold = 1}) {
109-
final newImage = image.quantize(srcImage);
104+
static image.Image _encodeGifWIthTransparency(image.Image srcImage, {int transparencyThreshold = 1}) {
105+
var format = srcImage.format;
106+
image.Image image32;
107+
if (format != image.Format.int8) {
108+
image32 = srcImage.convert(format: image.Format.uint8);
109+
} else {
110+
image32 = srcImage;
111+
}
112+
final newImage = image.quantize(image32);
110113

111114
// GifEncoder will use palette colors with a 0 alpha as transparent. Look at the pixels
112115
// of the original image and set the alpha of the palette color to 0 if the pixel is below
@@ -121,8 +124,7 @@ class Exporter {
121124
for (final srcPixel in srcFrame) {
122125
if (srcPixel.a < transparencyThreshold) {
123126
final newPixel = newFrame.getPixel(srcPixel.x, srcPixel.y);
124-
palette.setAlpha(
125-
newPixel.index.toInt(), 0); // Set the palette color alpha to 0
127+
palette.setAlpha(newPixel.index.toInt(), 0); // Set the palette color alpha to 0
126128
}
127129
}
128130

0 commit comments

Comments
 (0)