处理以前删除的答案,可以通过有一个图像,而另一个图像绝对位于顶部来实现。
“后退”图像使用tintColor,如https://facebook.github.io/react-native/docs/image.html所定义,这会将所有不透明的像素变为该颜色。
在“正面”图像上添加了不透明度,从而使“背面”颜色向前移动,从而为您提供“灰度”图像
之前:
<React.Fragment>
<Image source={<something>} />
</React.Fragment>
Run Code Online (Sandbox Code Playgroud)
之后(带有背景图片):
<React.Fragment>
<Image source={<something>} style={{ tintColor: 'gray' }} />
<Image source={<something>} style={{ position: 'absolute', opacity: 0.3}} />
</React.Fragment>
Run Code Online (Sandbox Code Playgroud)
红色为tintColor:
您可以使用我的react-native-color-matrix-image-filters库:
import { Image } from 'react-native';
import { Grayscale } from 'react-native-color-matrix-image-filters';
const GrayscaledImage = (imageProps) => (
<Grayscale>
<Image {...imageProps} />
</Grayscale>
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9040 次 |
| 最近记录: |