gpt4 book ai didi

flutter - 如何在 flutter 中使用混合混合模式?

转载 作者:行者123 更新时间:2023-12-03 13:28:45 26 4
gpt4 key购买 nike

我尝试了似乎只适用于颜色的混合模式,即colorblendmode。有什么方法可以实现mix-blend-mode as of CSS吗?

  Stack(
children: <Widget>[
Image.asset(
"asset/text.PNG",
height: double.maxFinite,
width: double.maxFinite,
fit: BoxFit.fitHeight,
color: Colors.red,
colorBlendMode: BlendMode.multiply,
),
Image.asset("asset/face.jpg",
width: double.maxFinite,
fit: BoxFit.fitHeight,
color: Colors.red,
colorBlendMode: BlendMode.multiply),
],
),
结果如下:
The output of code above
我想得到什么
Output from CSS

最佳答案

尝试ShaderMask
BlendModes
使用示例:

import 'dart:async';
import 'dart:typed_data';
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SafeArea(
child: MyHomePage(),
),
),
);
}
}

class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Future<ui.Image> loadUiImage(String imageAssetPath) async {
final data = await rootBundle.load(imageAssetPath);
final completer = Completer<ui.Image>();
ui.decodeImageFromList(Uint8List.view(data.buffer), completer.complete);
return completer.future;
}

@override
Widget build(BuildContext context) {
return FutureBuilder<ui.Image>(
future: loadUiImage('assets/cara_img.png'),
builder: (context, img) {
return img.hasData
? ShaderMask(
blendMode: BlendMode.colorDodge,
shaderCallback: (bounds) => ImageShader(
img.data,
TileMode.clamp,
TileMode.clamp,
Matrix4.identity().storage,
),
child: Image.asset('assets/code.png'),
)
: Container(
color: Colors.red,
height: 100,
width: 100,
child: Text('loading'),
);
});
}
}
code.png:
code.png
cara_img.png:
cara_img.png
结果:
enter image description here
enter image description here
enter image description here

关于flutter - 如何在 flutter 中使用混合混合模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62620579/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com