本文介绍了Dart中的图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了可识别图片元素的应用。
现在我在File类中有图像,我想将图像旋转几度,然后再次在File类中有图像。
有解决方案吗?

I create app which recognize elements from picture.Now I have image in File class and I want to rotate image about few degrees and again have image in File class.Is there any solution how to resolve this?

P.S我不想显示此图像。我必须将图像作为File对象传递给某些方法。

P.S I don't want display this image. I must pass image as File object to some method.

推荐答案



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));
}



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"),);

这篇关于Dart中的图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 18:48
查看更多