发布于 2016-05-18 19:38:06
你使用的库是uses a webview,因此你没有可以保存的图像。要以概念性的方式保存二维码,您可以存储提供的值,并根据需要将其放入组件中。如果需要获取图像,则需要扩展webview javascript part以使用画布的the ImageData interface。这是一个非常棘手的问题,我甚至不能完全确定是否有可能从web视图中获取数据。
发布于 2020-10-21 16:07:54
使用rn-qr-generator生成二维码。它将返回生成图像的路径或base64。稍后,您可以使用CameraRoll模块将图像存储在CameraRoll (或android上的Gallery )中。
import RNQRGenerator from 'rn-qr-generator';
import CameraRoll from "@react-native-community/cameraroll";
RNQRGenerator.generate({
value: 'your_qr_string_value_here',
height: 100, // height of the output image
width: 100, // width of the output image
base64: false, // default 'false'
backgroundColor: 'black', // default 'white'
color: 'white', // default 'black'
})
.then(response => {
const { uri, width, height, base64 } = response;
this.setState({ imageUri: uri });
CameraRoll.save(uri);
})
.catch(error => console.log('Cannot create QR code', error));
在调用CameraRoll.save
之前,请确保您具有保存图像的权限。权限示例请参见here。
https://stackoverflow.com/questions/36371883
复制相似问题