Flutter rotated image background color black issue - flutter

I'm using this Rotate function in Flutter application but if I use this rotated image the background color will be black but I need the background color in the image to be white.
Future rotateImage(String imagePath, double rotationValue) async {
File imageFile = File(imagePath);
var decodedImage = await decodeImageFromList(imageFile.readAsBytesSync());
List<int> imageBytes = await imageFile.readAsBytes();
var originalImage = img.decodeImage(Uint8List.fromList(imageBytes));
img.Image fixedImage = img.copyRotate(originalImage!,
angle: rotationValue, interpolation: img.Interpolation.average);
var fixedFile = await imageFile.writeAsBytes(img.encodePng(
fixedImage,
));
return fixedFile;
}
It would be appreciated if anyone could help me

Related

How to get width and height from picked image XFile?

I'm trying to resize and compress the image file (XFile) picked by image_picker package
But I don't where to get the image information (width, height)
I tried image_size_getter package but I got an unsupported exception
Is there an easy way to get the width and height from XFile?
you can try this:
XFile? imageFile = await ImagePicker().pickImage(source: ImageSource.camera);
if (imageFile != null) {
final decodedImage = await decodeImageFromList(await imageFile.readAsBytes());
final height = decodedImage.height; // Image height
final width = decodedImage.width; // Image width
}
Using the below code you are able to get different things of Image
import 'dart:io';
XFile? image = await ImagePicker().pickImage(source: ImageSource.gallery);
var decodedImage = await decodeImageFromList(image.readAsBytesSync());
print(decodedImage.width);
print(decodedImage.height);

Can't get image file through image picker in flutter

i can't get images file through image picker in flutter.
void _getImage() async {
print("getImage");
final ImagePicker picker = ImagePicker();
XFile? image = await picker.pickImage(source: ImageSource.gallery);
print(image);
}
and error's occur, look at this
enter image description here
my enviroment is M1 pro, ios15.2
Try this
_getImage(BuildContext context) async {
var picture = await ImagePicker().pickImage(source: ImageSource.gallery);
setState(() {
imageFile = File(picture!.path);
dirPath = picture.path;
print('path');
print(dirPath);
});
}

Image Picker Flutter and Progress Indicator

I have implmented image picker, it is working great on both ios and android.
However, after i have captured an image, it is taking quite long for it to appear on my Image.file(image) widget.
I cannot decrease the quality of image, as it matters in the app.
So i need something like CachedNetworkImage but to load from file, not from internet, any ideas?
I just want to show an progress bar or indicator, just to let the user know that there is a process.
File? image;
Future pickImage(ImageSource source, BuildContext context) async {
try {
final image = await ImagePicker().pickImage(source: source);
if (image == null) return;
var imageTemporary = File(image.path);
if (source == ImageSource.camera) {
final img.Image? capturedImage =
img.decodeImage(await File(image.path).readAsBytes());
final img.Image orientedImage = img.bakeOrientation(capturedImage!);
imageTemporary =
await File(image.path).writeAsBytes(img.encodeJpg(orientedImage));
}
setState(() {
this.image = imageTemporary;
});
} on PlatformException catch (e) {print(e.toString());}
}
Thats my function to call image picker.
And passing it to ElevatedButton like:

Flutter for loop causes laggy loading animation

I build a for loop in Flutter on which I make some stuff with many images:
for (var i = 0; i < resultList.length; i++) {
File imageFile = await _getImageFileFromAssets(resultList[i]);
final appDir = await syspath.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path);
final savedImage =
await File(imageFile.path).copy('${appDir.path}/$fileName');
// Creating thumbnails
final thumb =
image.decodeImage(File(savedImage.path).readAsBytesSync());
final thumbImage = image.copyResize(thumb, width: 500);
new File('${appDir.path}/$fileName-thumb-500.jpg')
.writeAsBytesSync(image.encodeJpg(thumbImage));
final finalThumbImage =
File('${appDir.path}/$fileName-thumb-500.jpg');
picturesData.add(Picture(
album: albumID,
path: savedImage.path,
thumbPath: finalThumbImage.path,
timestamp: Timestamp.now()));
setState(() {
loadingScreen = true;
});
}
While the loop is working, I show a loading screen Widget with an loading animation:
return loadingScreen == true ? LoadingScreen() : Scaffold()
What I expect A clean loading screen while the for loop duration with smooth animation
What I get Extreme flickering and lagging on the animation. After each image was edited, the animation stops. So I get something like a stop motion animation.
What could be the issue here?

App crashes when back button press while picking Image

My flutter app crashes when pressing of back button while picking an image.How can I solve that?
Here is Image picking part
_openGallery(BuildContext context) async{
var picture = await ImagePicker.pickImage(source: ImageSource.gallery);
this.setState((){
imageFile = picture;
});
if (picture==null) {
Navigator.of(context).pop();
} else{
final File newImage = await imageFile.copy('$_localPath/name.jpg');
}
Navigator.of(context).pop();
}