我正在尝试将图像文件绘制到画布中以在Flutter中组成我的小部件。
我确实遵循了画布文档,但是没有成功。O Image docs,说:
要获取Image对象,请使用InstantiateImageCodec。
我确实尝试过使用instantiateImageCodec方法,但是我只是得到一个Codec实例,而不是图像
如何使用ui.Image实例在画布上绘制的正确方法 canvas.drawImage
这是我的代码的摘要:
Future<ui.Codec> _loadImage(AssetBundleImageKey key) async {
final ByteData data = await key.bundle.load(key.name);
if (data == null)
throw 'Unable to read data';
return await ui.instantiateImageCodec(data.buffer.asUint8List());
}
final Paint paint = new Paint()
..color = Colors.yellow
..strokeWidth = 2.0
..strokeCap = StrokeCap.butt
..style = PaintingStyle.stroke;
var sunImage = new ExactAssetImage("res/images/grid_icon.png");
sunImage.obtainKey(new ImageConfiguration()).then((AssetBundleImageKey key){
_loadImage(key).then((ui.Codec codec){
print("frameCount: ${codec.frameCount.toString()}");
codec.getNextFrame().then((info){
print("image: ${info.image.toString()}");
print("duration: ${info.duration.toString()}");
canvas.drawImage(info.image, size.center(Offset.zero), paint);
}); …Run Code Online (Sandbox Code Playgroud) 我有一个Android应用程序要发布,今天尝试运行API 22的设备Moto G,我遇到了以下错误:
java.security.NoSuchAlgorithmException: 未找到KeyGenerator RSA 实现
众所周知,相同的应用程序在较新的设备API 23+上正常运行
查询Google文档,我发现自API +1以来支持AES算法,我不明白发生了什么.
有没有人遇到过这个问题?
顺便说一句,我正在尝试生成加密Realm数据的密钥.
private static final String KEYSTORE_PROVIDER_NAME = "AndroidKeyStore";
public void generateKeyInKeystore() {
final KeyGenerator keyGenerator;
try {
keyGenerator = KeyGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES,
KEYSTORE_PROVIDER_NAME);
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
throw new RuntimeException(e);
}
final KeyGenParameterSpec keySpec;
try {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
keySpec = new KeyGenParameterSpec.Builder(
KEY_ALIAS,
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.setUserAuthenticationRequired(false)
.build();
keyGenerator.init(keySpec);
}
} catch (InvalidAlgorithmParameterException e) {
throw new RuntimeException(e);
}
keyGenerator.generateKey(); …Run Code Online (Sandbox Code Playgroud)