如何使用 react-native-qrcode 保存生成的二维码 [英] how to save the generated QR-code using react-native-qrcode
问题描述
我正在尝试使用此模块生成二维码
I am trying to generate QR code, by using this module 'react-native-qrcode', Here I got generated QR code like this, How can I save this QR code.
谁能给我建议如何保存这个生成的 qr,非常感谢任何帮助
Can anyone give me suggestions that how to save this generated qr,any help much appreciated
推荐答案
使用 rn-qr-generator 生成二维码.它将返回生成图像的路径或 base64.稍后您可以使用 CameraRoll 模块将图像存储在 CameraRoll(或安卓上的图库).
Use rn-qr-generator to generate a QR code. It will return a path or base64 of generated Image. Later you can use CameraRoll module to store the image in CameraRoll (or Gallery on android).
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
之前,请确保您有保存图像的权限.权限示例请参见此处.
Before calling CameraRoll.save
make sure you have permission to save the image. Permission example see here.
这篇关于如何使用 react-native-qrcode 保存生成的二维码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!