在Reaction Native中,有没有办法以编程方式使图像经过黑白过滤?我有一些白色背景和彩色字母的图像.我希望这些字母都是黑色的,这样它们就很容易辨认出来.
在Reaction Native中,有没有办法以编程方式使图像经过黑白过滤?我有一些白色背景和彩色字母的图像.我希望这些字母都是黑色的,这样它们就很容易辨认出来.
需要style
props 才能对图像应用灰度滤镜.以下是您如何做到这一点的一个示例:
import React from 'react';
import { Image, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
image: {
filter: 'grayscale(100%)', // You can adjust the intensity of the grayscale accoding. value of 0% will produce a normal images.
},
});
图像组件中的灰度(100%)滤镜,它将生成黑白.
const MyImage = () => {
return (
<Image
source={require('./my-image.png')}
style={styles.image}
/>
);
};
export default MyImage;