我似乎无法简单地将硬盘中的图像加载到屏幕上.Image.net工作似乎很简单.但我无法弄清楚如何使用Image或Image.file.图像似乎需要一个流,所以我认为这不是我想要的.
import 'package:flutter/material.dart';
import 'dart:io';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
File file = new File("Someimage.jpeg");
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Image.file(file), //doesn't work, but no errors
);
}
}
Run Code Online (Sandbox Code Playgroud)
我将someimage添加到pubspec.yaml文件中,但这也不起作用:
assets:
- Someimage.jpeg
Run Code Online (Sandbox Code Playgroud)
有人能给我一个如何做到这一点的例子吗?谢谢.
我正在使用Flutter将"资产"加载到File一个本地应用程序可以访问它.
这是我加载资产的方式:
final dbBytes = await rootBundle.load('assets/file');
Run Code Online (Sandbox Code Playgroud)
这将返回一个实例ByteData.
如何将其写入dart.io.File实例?
如何将图像文件转换为二进制数据?我正在使用一个名为 image_picker 的库来从图库或相机中选择图像。我想将我选择的图像转换为二进制数据。
File image = await ImagePicker.pickImage(source: ImageSource.gallery)
(image as Image).toByteData // the method toByteData here is not pop up.
Run Code Online (Sandbox Code Playgroud)