- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图从我的测试设备相机胶卷中获取图像以呈现为缩略图。我已成功从相机胶卷中获取图像并将它们显示在 ListView 中的一系列 Image 元素中,但加载它们需要很长时间。此外,我在 React Native 文档中读到 Image 元素将选择将渲染到的空间的正确图像大小。
这是来自文档。
iOS saves multiple sizes for the same image in your Camera Roll, it is very important to pick the one that's as close as possible for performance reasons. You wouldn't want to use the full quality 3264x2448 image as source when displaying a 200x200 thumbnail. If there's an exact match, React Native will pick it, otherwise it's going to use the first one that's at least 50% bigger in order to avoid blur when resizing from a close size. All of this is done by default so you don't have to worry about writing the tedious (and error prone) code to do it yourself. 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}
/>
}
最佳答案
好的,这是可能的,但您必须将手放在 react-native 的 Objective-C 派对中。
您可以查看 this .
您必须修改 RCTCameraRollManager.m 文件。
你必须添加这些行:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
NSURL *url = [[NSURL alloc] initWithString:uri];
[library assetForURL:url resultBlock:^(ALAsset *asset) {
// Create an ALAssetRepresentation object using our asset
// and turn it into a bitmap using the CGImageRef opaque type.
CGImageRef imageRef = [asset thumbnail];
CGSize dimensions = [UIImage imageWithCGImage:imageRef].size;
// Create UIImageJPEGRepresentation from CGImageRef
NSData *imageData = UIImageJPEGRepresentation([UIImage imageWithCGImage:imageRef], 0.1);
[assets addObject:@{...}]
方法并添加:
} failureBlock:^(NSError *error) {
NSLog(@"that didn't work %@", error);
}];
[assets addObject:@{...}]
方法。
@"base64": base64Encoded
在
[assets addObject:@{
方法。
关于react-native - React Native - 如何获取相机胶卷缩略图而不是全尺寸图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32641345/
我是一名优秀的程序员,十分优秀!