我已经看到了使用ImageElement加载图像的答案.这仅适用于浏览器端,我想在服务器上进行一些处理.
有没有办法从服务器端dart中的PNG加载和读取RGBA值?如果没有计划的服务器端图像处理库?
无论如何运行Dartium"无头"所以我可以使用画布api做我想要的吗?
小智 5
有一个dart库,可以读写服务器端的PNG图像, http://pub.dartlang.org/packages/image
该库可以读取和写入PNG和JPG图像,并提供许多图像处理命令.
例如,要读取PNG,请调整其大小,然后使用此库将其保存到磁盘:
import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
// Read a PNG image from file.
Image image = readPng(new Io.File('foo.png').readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
// Save the thumbnail to disk as a PNG.
new Io.File('foo-thumbnail.png').writeAsBytesSync(writePng(thumbnail));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
870 次 |
| 最近记录: |