image
image copied to clipboard
How to display Image in a container without encode it ?
Currently, I take a photo with the camera, then I decode it and finally I crop it. I would like to display this image in a container but the only way I found is to encode in PNG and then use DecorationImage on the File but the processing time is too long (even with level: 1). I would like it to be as fast as possible. So I would like to display the image without going through the encoding, is that possible?
import 'package:image/image.dart' as Image;
// Get Img
final image = await _controller.takePicture();
// Get Path
_imageFile = File(image.path);
// Decode
Image.Image image_decode =
Image.decodeImage(_imageFile.readAsBytesSync())!;
// Crop
Image.Image image_crop = Image.copyCrop(
image_decode,
left_crop.toInt(),
top_crop.toInt(),
width_crop.toInt(),
height_crop.toInt());
// I want to display img from here....
// Save Img
String tempDir = (await getApplicationDocumentsDirectory()).path;
var pathImg = "${tempDir}/temp.png";
File compressedImage = new File(pathImg)
..writeAsBytesSync(Image.encodePng(image_crop, level: 1));
// Display
Container(
height: h_display,
width: w_display,
decoration: BoxDecoration(
border:
Border.all(width: 5, color: Colors.grey.shade400),
color: Colors.white,
borderRadius: BorderRadius.circular(15),
image: DecorationImage(
image: FileImage(File(compressedImage.path)) as ImageProvider,
fit: BoxFit.fill,
),
),
),
I'd love to have a good solution for this too
Unfortunately I don't have any control over Flutter, or their lack of support for creating images from byte data.