我已经成功地在我的应用程序中拍摄照片并将其存储在手机上,但我该如何显示它?
我尝试了这种静态方法,但它不起作用(是的,图像在那里:))
<Image width={40} height={40} source={{uri: '/storage/emulated/0/DCIM/IMG_20161201_125218.jpg'}} />
答案 0 :(得分:9)
即使我遇到了这个问题并得到了解决。你必须在file://前面添加文件路径(注意双/)。
<Image source{{uri:'file:///storage/emulated/0/DCIM/IMG_20161201_125218.jpg'}} style={myImageStyle}/>
这里是reference!
我希望这会有所帮助:)
答案 1 :(得分:1)
// import
import { PermissionsAndroid } from "react-native";
// function to request permission
requestStoragePermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
title: "Permission title",
message:
"Permission message",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK",
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("You can use the EXTERNAL_STORAGE");
} else {
console.log("EXTERNAL_STORAGE permission denied");
}
} catch (err) {
console.warn(err);
}
};
<Button title="request permissions" onPress={this.requestStoragePermission} />
答案 2 :(得分:0)
<Image source = {{uri: "file:///storage/emulated/0/appiwell/image/qkpOyUaRla.jpg",
width: responsiveWidth(100),
height: responsiveHeight(100)}}/>
注意,应在{uri,width,height}内设置宽度,高度。宽度,高度的风格可能不起作用。
responsiveWidth,responsiveHeight here https://www.npmjs.com/package/react-native-responsive-dimensions