我想從我的測試設備相機卷獲取圖像以縮略圖形式呈現。我已成功從相機膠捲中提取圖像,並將它們顯示在列表視圖中的一系列圖像元素中,但它們需要很長時間才能加載。另外,我在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解決方案? –