Skip to content

[palette_generator]Fix PaletteGenerator.fromImageProvider region not scaled to fit image size. #200

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

Merged
merged 3 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/palette_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.4

* Fix PaletteGenerator.fromImageProvider region not scaled to fit image size.

## 0.2.3

* Bumped minimum Flutter version to 1.15.21 to pick up Diagnosticable as a mixin and remove DiagnosticableMixin.
Expand Down
15 changes: 13 additions & 2 deletions packages/palette_generator/lib/palette_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,20 @@ class PaletteGenerator with Diagnosticable {
});
}
stream.addListener(listener);
final ui.Image image = await imageCompleter.future;
ui.Rect newRegion = region;
if (size != null && region != null) {
final double scale = image.width / size.width;
newRegion = Rect.fromLTRB(
region.left * scale,
region.top * scale,
region.right * scale,
region.bottom * scale,
);
}
return PaletteGenerator.fromImage(
await imageCompleter.future,
region: region,
image,
region: newRegion,
maximumColorCount: maximumColorCount,
filters: filters,
targets: targets,
Expand Down
2 changes: 1 addition & 1 deletion packages/palette_generator/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: palette_generator
description: Flutter package for generating palette colors from a source image.
homepage: https://github.com/flutter/packages/tree/master/packages/palette_generator
version: 0.2.3
version: 0.2.4

dependencies:
flutter:
Expand Down