我的API响应时图像尺寸为1280X720,我在应用中仅使用110X110尺寸。我认为,这也增加了加载时间和内存消耗。如何处理这些情况。如何优化我的代码?
答案 0 :(得分:0)
您可以使用此plugin压缩图像并调整其大小。
npm install --save react-native-image-resizer
react-native link react-native-image-resizer
代码示例:
import ImageResizer from 'react-native-image-resizer';
ImageResizer.createResizedImage(imageUri, newWidth, newHeight, compressFormat, quality, rotation, outputPath).then((response) => {
// response.uri is the URI of the new image that can now be displayed, uploaded...
// response.path is the path of the new image
// response.name is the name of the new image with the extension
// response.size is the size of the new image
}).catch((err) => {
// Oops, something went wrong. Check that the filename is correct and
// inspect err to get more details.
});