android - Dart中的图像处理

标签 android flutter dart

我创建的应用程序可以识别图片中的元素。
现在我在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 an AlwaysStoppedAnimation 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/

相关文章:

regex - 如何在 Dart 中使用正则表达式?

random - 在 Dart 中生成唯一的随机数

flutter - 操作系统错误:连接被对等方重置,errno = 104,地址= storage.googleapis.com,prort = 37890

java - 如何使用 Retrofit 在后台定期从服务器获取数据

android - 在不同设备上呈现不同的颜色

javascript - 检测客户端是否允许 HTML5 视频的内​​联媒体播放

java - Android Studio 0.1.1 gradle 项目中的 Google Play 服务?

layout - 使用 Align 或使用 Positioned flutter 有什么区别

google-chrome - 如何在 Windows 中为 Dart 以选中模式启动 Dartium/Chrome?

android - 参数类型 'Color?' 不能分配给参数类型 'MaterialColor?