-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Web: Image shrinks when editted #37
Comments
This could be because I have this image inside a Widget with a FittedBox and it's scaled to fit. I scanned your code and I don't understand how it works, but I see you are taking screenshots? Maybe you should use the PictureRecorder() and draw to a canvas? Screenshots seems like a weird thing to do, but I know nothing about how the code works.
|
Hi Steve Don't worry, I know the Anyway, I just tested it and everything works fine for me without scaling down the image. So now my questions:
Code screenshot package: Future<Uint8List?> capture({
double? pixelRatio,
Duration delay = const Duration(milliseconds: 20),
}) {
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return new Future.delayed(delay, () async {
ui.Image? image = await captureAsUiImage(
delay: Duration.zero,
pixelRatio: pixelRatio,
);
ByteData? byteData =
await image?.toByteData(format: ui.ImageByteFormat.png);
image?.dispose();
Uint8List? pngBytes = byteData?.buffer.asUint8List();
return pngBytes;
});
}
Future<ui.Image?> captureAsUiImage(
{double? pixelRatio = 1,
Duration delay = const Duration(milliseconds: 20)}) {
//Delay is required. See Issue https://github.com/flutter/flutter/issues/22308
return new Future.delayed(delay, () async {
try {
var findRenderObject =
this._containerKey.currentContext?.findRenderObject();
if (findRenderObject == null) {
return null;
}
RenderRepaintBoundary boundary =
findRenderObject as RenderRepaintBoundary;
BuildContext? context = _containerKey.currentContext;
if (pixelRatio == null) {
if (context != null)
pixelRatio = pixelRatio ?? MediaQuery.of(context).devicePixelRatio;
}
ui.Image image = await boundary.toImage(pixelRatio: pixelRatio ?? 1);
return image;
} catch (e) {
throw e;
}
});
} |
I just opened an image i painted on and saved it again and it shrank
Chrome
I use a file picker package for web that lets me pick a file on disk and it gives me the file bytes
regular
ProImageEditor.memory( I do some experiments and see what I find. |
I think I figured it out. The size of the dialog matters. I think when you create the image you are looking at the context of the dialog that is not as wide or tall as the main window and some calculation is wrong? |
Yeah, I confirmed it in the example app. replace the MaterialPageRoute with this new dialog route to see it happen.
|
I'm assuming a bug in TransformHelper? I would get rid of that screenshot stuff and just draw everything in a canvas. Seems much simpler. Not sure how the pixel ratio stuff works, but is that just drawing the image in a larger or smaller canvas and stretching or shrinking it? I'm sure you can do everything in Canvas. drawImage, drawImageRect, drawPicture, paths etc. dragging and dropping text and emojis also has some math problems when inside a dialog. Maybe the same issue. |
Thanks Steve, for this detailed answer which helped me a lot. I reproduced it and found out that the problem before was that for all calculations I checked the full-screen size “MediaQuery.of(context).size” which of course will make problems when the “ProImageEditor” is rendered in smaller sizes. So every time you saved your changes, the pixel Ratio was calculated for a full-screen size, which scaled it down. However, I made some changes in version To the part about Canvas: |
seems to work. Thanks! |
Package Version
2.7.3
Flutter Version
3.19
Platforms
Web
How to reproduce?
I edit an image and the result is smaller
![Screenshot-20240506155433-809x995](https://private-user-images.githubusercontent.com/287137/328338658-a7c81376-295e-44c6-a543-9eb55bf89704.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA4NTEyNTUsIm5iZiI6MTcyMDg1MDk1NSwicGF0aCI6Ii8yODcxMzcvMzI4MzM4NjU4LWE3YzgxMzc2LTI5NWUtNDRjNi1hNTQzLTllYjU1YmY4OTcwNC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxM1QwNjA5MTVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jNjQyYzQwMTU5MDVhNjc5N2VlOWY5MjBhYjI0ODUzYTQ3YmQwODYxNDU4NzRlZmFmMzg2NTM0NGVjNzQ5NmFhJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.xoCN3F00a8asx1OO_8iGYcFmZuklSAtVRItuOe3ITwM)
Logs (optional)
Example code (optional)
No response
Device Model (optional)
linux
The text was updated successfully, but these errors were encountered: