我想从我的测试设备相机卷获取图像以缩略图形式呈现。我已成功从相机胶卷中提取图像,并将它们显示在列表视图中的一系列图像元素中,但它们需要很长时间才能加载。另外,我在React Native文档中阅读了图像元素将选择正确的图像大小为它将呈现的空间。React Native - 如何获取相机卷缩略图而不是全尺寸图像
这是来自文档。
iOS为您的相机胶卷中的相同图像保存了多种尺寸,因此出于性能原因选择尽可能接近的尺寸非常重要。显示200x200缩略图时,您不希望将全质量3264x2448图像用作来源。如果有完全匹配,则React Native会选择它,否则它将使用第一个至少大50%以避免从缩小尺寸调整大小时产生模糊。所有这些都是默认完成的,因此您不必担心编写繁琐(容易出错)的代码来自行完成。 https://facebook.github.io/react-native/docs/image.html#best-camera-roll-image
我用来读取图像的代码非常简单。
CameraRoll.getPhotos({
first: 21,
assetType: 'Photos'
}, (data) => {
console.log(data);
var images = data.edges.map((asset) => {
return {
uri: asset.node.image.uri
};
});
this.setState({
images: this.state.images.cloneWithRows(images)
});
},() => {
this.setState({
retrievePhotoError: messages.errors.retrievePhotos
});
});
然后渲染它我有这些功能。
renderImage(image) {
return <Image resizeMode="cover" source={{uri: image.uri}} style={[{
height: imageDimensions, // imageDimensions == 93.5
width: imageDimensions
}, componentStyles.thumbnails]}/>;
},
render() {
<ListView
automaticallyAdjustContentInsets={false}
contentContainerStyle={componentStyles.row}
dataSource={this.state.images}
renderRow={this.renderImage}
/>
}
我在这里错过了什么?我要疯了!!!
您是否使用javascript解决方案? –