javascript - 无法下载 png 格式的二维码
问题描述
我正在使用 QRCode-SVG 绘制 QRCode,amd 能够通过我的应用程序生成 QRCode,但是在生成 qr 码后,我试图在长按时以 png 格式保存/下载/共享它。安装并生成 qr 码后我正在按下 qrcode,它要求访问画廊,但在证明访问得到错误“未定义不是函数(评估 '_iteratortypeof Symbol === "function"?Symbol.iterator:"@@iterator"') 之后
import React, { Component } from 'react';
//import react in our code.
import { StyleSheet, View,TextInput, TouchableOpacity, Text,} from 'react-native';
// import all basic components
import Share from 'react-native-share'
import QRCode from 'react-native-qrcode-svg';
//import QRCode
class App extends Component {
svg;
constructor() {
super();
this.state = {
inputValue: '',
inputValue2: '',
// Default Value of the TextInput
valueForQRCode: '',
// Default value for the QR Code
};
}
getTextInputValue = () => {
// Function to get the value from input
// and Setting the value to the QRCode
this.setState({ valueForQRCode: this.state.inputValue + this.state.inputValue2 });
};
shareQR =() =>{
this.svg.toDataURL((data) => {
const shareImageBase64 = {
title: "QR",
message: "Ehi, this is my QR code",
type: 'image/png',
url: `data:image/png;base64,${data}`
};
Share.open(shareImageBase64);
});
}
render() {
return (
<View style={styles.MainContainer}>
{/* <QRCode
value={"Abhigyan" + this.state.valueForQRCode}
size={250}
bgColor="#000"
fgColor="#fff"
getRef={(ref) => (this.svg = ref)}
onPress={() =>{shareQR()}}
/> */}
<TouchableOpacity onPress={this.shareQR}>
<QRCode
value={"," + this.state.valueForQRCode}
size={250}
fgcolor="#fff"
bgColor="#000"
getRef={(ref) => (this.svg = ref)}
/>
</TouchableOpacity>
<TextInput
// Input to get the value to set on QRCode
style={styles.TextInputStyle}
onChangeText={text => this.setState({ inputValue: text })}
underlineColorAndroid="transparent"
placeholder="Enter text to Generate QR Code"
/>
<TextInput
// Input to get the value to set on QRCode
style={styles.TextInputStyle}
onChangeText={text => this.setState({ inputValue2: text })}
underlineColorAndroid="transparent"
placeholder="Enter text to Generate QR Code"
/>
<TouchableOpacity
onPress={this.getTextInputValue}
activeOpacity={0.7}
style={styles.button}>
<Text style={styles.TextStyle}> Generate QR Code </Text>
</TouchableOpacity>
</View>
);
}
}
export default App;
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
margin: 10,
alignItems: 'center',
paddingTop: 40,
},
TextInputStyle: {
width: '100%',
height: 40,
marginTop: 20,
borderWidth: 1,
textAlign: 'center',
},
button: {
width: '100%',
paddingTop: 8,
marginTop: 10,
paddingBottom: 8,
backgroundColor: '#F44336',
marginBottom: 20,
},
TextStyle: {
color: '#fff',
textAlign: 'center',
fontSize: 18,
},
});
我的 git 链接 - https://github.com/abhigyan9301/QRCode
解决方案
推荐阅读
- c# - 在运行时将数据绑定到 XAML
- javascript - 反应本地文件夹中的本地调用动态图像
- django - [DJANGO][GUNICORN] 不允许操作
- java - 验证是否存在唯一字符串的组合
- c# - 访问 ListboxItem 中的控件
- python - 为什么 2 * x * x 在 Python 3.x 中比 2 * ( x * x ) 快,对于整数?
- javascript - .Net 服务器上类似浏览器的体验
- ionic-framework - 错误:IonTextAvatar 类型是 2 个模块声明的一部分:离子
- puppet - 评估资源语句时出错,未知资源类型:'::coldfusion::site'
- android - 右键和左键单击 ViewPager