我创建的应用程序可以识别图片中的元素。
现在我在File类中有图像,我想将图像旋转几度,然后再次在File类中有图像。
请问有什么解决办法吗?
附言:我不想显示此图像。我必须将图像作为File对象传递给某些方法。
最佳答案
To rotate the actual file in memory use the image library and the copyRotate function.
Image copyRotate(Image src, num angle, {
Interpolation interpolation = Interpolation.nearest
}
);
//Returns a copy of the [src] image, rotated by [angle] degrees.
例:
import 'dart:io';
import 'package:image/image.dart';
void main() {
// Read an image from file (webp in this case).
// decodeImage will identify the format of the image and use the appropriate
// decoder.
Image image = decodeImage(File('test.webp').readAsBytesSync());
Image thumbnail = copyRotate(image, 120);
// Save the thumbnail as a PNG.
File('thumbnail.png').writeAsBytesSync(encodePng(thumbnail));
}
source
To display a rotated version of the image stored, you can use a
RotationTransition
with anAlwaysStoppedAnimation
like-
new RotatedBox(
quarterTurns: 1,
child: new Text("Lorem ipsum")
)
或
Transform.rotate()
小部件- Transform.rotate(angle: - math.pi / 4, child: Text("Text"),);
对于您的用例-
Transform.rotate(angle: degrees*3.14/180, child: Image.asset("file_path"),);
关于android - Dart中的图像处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59413941/