Open thanglq1 opened 1 month ago
I just tried your code, but I can't reproduce it. I used many different image ratios, but in my case it always works. Actually, it should not matter what kind of ratio the image has. However, can you try for me with an image that is in “JPEG” format that has the same ratio as the one that is causing a problem?
The point is, currently I think there is an issue with decoding your image. I saw in the example URL which you posted it automatically choose the format. Keep in mind that Flutter can make problems by decoding more modern image formats like “AVIF” so I recommend you to use jpeg/png. Alternative you can download it in a modern format, but before you insert it in the image editor you use an external package that converts it in a format that Flutter can decode.
In the case, the same issue is also with the format “JPEG” do you get any error in the console when you open the image? And on which exactly device you test it? Happen the issue also on other devices and also on the platforms windows and web?
You're right. The image ratio doesn't matter. I've tried several images with different ratios, and sometimes it works, sometimes it doesn't. The image format is .jpg. I've tested on both an iPhone 15 simulator (iOS 17) and a Samsung Galaxy A71 (Android 13. Real device). The error occurs on both devices. Currently, I haven't found a pattern because sometimes the same image works without any error. It also doesn't throw any exceptions.
Sometimes the captureFinalScreenshot
method in content_recorder_controller.dart
returns null.
if (activeScreenshotGeneration) {
// Get screenshot from isolated generated thread.
bytes = await backgroundScreenshot.completer.future;
} else {
// Capture a new screenshot if the current screenshot is broken or
// doesn't exist.
bytes = widget == null
? await _capture(
id: id,
imageInfos: imageInfos,
)
: await captureFromWidget(
widget,
id: id,
targetSize: targetSize,
imageInfos: imageInfos,
);
}
Sometimes it goes to the 'if' block, sometimes to the 'else' block, and returns null. So in the following code:
Uint8List? bytes = await screenshotCtrl.captureFinalScreenshot(
imageInfos: imageInfos!,
context: context,
widget: _screenshotWidget(transformC),
targetSize:
_rotated90deg ? imageInfos!.rawSize.flipped : imageInfos!.rawSize,
backgroundScreenshot:
screenshotHistoryPosition >= screenshotHistory.length
? null
: screenshotHistory[screenshotHistoryPosition],
);
bytes is null in the done()
method in crop_rotate_editor.dart
. That's why it returns zero bytes.
Here's the corrected version:
STEP is the same video. Just pick an image and then click the Done
button on the top right. Don't do anything else. Don't click Flip
, Ratio
Thank you for this information, that's good to know and help me to fix it. Can you also answer me the questions below that will help me to fix it.
Currently, from that what you describe, it sounds to me that the editor didn't capture the image. I'm not sure if the problem is that the editor didn't await to finish the capture progress, or it never started, but I think more that the problem is the editor didn't start to capture it.
Thanks for your help.
hideFakeHero
and takeScreenshot
are called.Okay, got it. When you print
the parameter screenshotHistoryPosition
and screenshotHistory.length
here which values does it show you?
Its always are screenshotHistoryPosition = 0
and screenshotHistory.length = 1
This is screenshotHistory
value when its working.
This is screenshotHistory
value when its error (case return zero bytes).
Ah okay, that's interesting, something seems to fail in the background generation that the state broken
is true. Actually, in this case the editor should re-capture an image when you press “done”, but it seems like that also fails. I'm not sure, but maybe something failed in the generation of the plain-transformed image. Can you check here if the size is correct when you press done?
The size is correct even if it returns data or returns zero bytes.
Okay, that's interesting. The problem is that I still can't reproduce it even after trying it on many mobile devices, so I don't think I can resolve this problem until I can reproduce it by myself.
I hope you can fix it soon. Thank you!
Hi @hm21. I can not reopen this issue. Please help reopen.
This issue needs time to fix.
Package Version
4.2.5
Flutter Version
3.22.2
Platforms
Android, iOS
How to reproduce?
Hi @hm21. I'm using the standalone Crop Editor, but it returns zero bytes (I guess the issue occurs with images that have a vertical ratio). It's working with images that have a horizontal ratio.
This is the video of the error (Image size: 1.7MB)
https://github.com/user-attachments/assets/98992dc0-a2c7-49e3-be46-9e3424a087c0
This is a video showing it working (Image size: 2.8MB)
https://github.com/user-attachments/assets/b2489ee6-9d32-47f9-8bfa-1792f43ce1ca
Original Image URL: https://images.unsplash.com/photo-1534794420636-dbc13b8a48d2?w=800&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fGJlYXV0aWZ1bCUyMGdpcmx8ZW58MHx8MHx8fDA%3D
Image file:![lerone-pieters-fX-j33IiF3Q-unsplash](https://github.com/user-attachments/assets/f8cfdc6c-14f8-4c71-94ef-3b4cf192aa5f)
Logs (optional)
No response
Example code (optional)
Device Model (optional)
No response