Skip to content
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

How do I get the pixels size of cropped image #149

Open
onism0106 opened this issue Mar 26, 2024 · 1 comment
Open

How do I get the pixels size of cropped image #149

onism0106 opened this issue Mar 26, 2024 · 1 comment

Comments

@onism0106
Copy link

No description provided.

@taufiqur0991
Copy link

in pubspec.yml use image: ^4.2.0
import 'package:image/image.dart' as img; // Import package image
onCropped: (croppedData) {

            setState(() {
              _croppedData = croppedData;
            });

        
            final decodedImage = img.decodeImage(_croppedData!);
            if (decodedImage != null) {
              int width = decodedImage.width;
              int height = decodedImage.height;
              print("Cropped image size: Width = $width, Height = $height");
            }
          },

or resize image
Uint8List _resizeImage(Uint8List imageData, int targetWidth, int targetHeight) {
final decodedImage = img.decodeImage(imageData);
if (decodedImage != null) {
// Resize gambar ke ukuran 300x400
final resizedImage = img.copyResize(decodedImage, width: targetWidth, height: targetHeight);
return Uint8List.fromList(img.encodeJpg(resizedImage)); // Bisa juga gunakan encodePng
}
return imageData;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants