通过摄像头拍摄的照片太大,无法在React native中高效上传和下载.

是否有api或库可以在React Native中压缩PNG图像文件?

推荐答案

https://github.com/bamlab/react-native-image-resizer提供了调整本 map 像大小的API.

它允许您指定:

  • 最大尺寸(同时保留纵横比)和;
  • 输出质量(仅适用于JPEG)

API

import ImageResizer from 'react-native-image-resizer';

ImageResizer.createResizedImage(imageUri, newWidth, newHeight, compressFormat, quality).then((resizedImageUri) => {
  // resizeImageUri is the URI of the new image that can now be displayed, uploaded...
}).catch((err) => {
  // Oops, something went wrong. Check that the filename is correct and
  // inspect err to get more details.
});

React-native相关问答推荐

React Native的TouchableOpacity不按类别获取样式名称

AxiosError:Reaction Native EXPO开发版本中的网络错误

使用react-native-reanimatedreact 导航崩溃

React Native 应用程序没有在之前的工作代码中执行任何操作就无法运行

如何停止在 textInput React Native 中输入空格?

react-native-snap-carousel 无法正确渲染

如何通过 node ID 获取真实元素?

更改整个 React Native App 的语言

iPhone 6s plus 上的字体大小

library not found for -lRCTGeolocation

React native Refresh 有效,但下一次调用仍使用最后一个令牌

如何在react native应用程序名称中添加空格?

如何从 stack.navigation 外部的组件中使用 navigation.navigate

React-Native 应用程序中来自 Babel 的未知选项错误

有react-native复选框的例子吗?

将 react-native 元素Bundle 为 iOS 框架或 (.aar) Android 库

React Native ScrollView 在 iOS 上从底部被截断

如何在自定义组件上使用 onPress?

如何知道 FlatList 中的滚动状态?

React Native 从导航堆栈中清除上一个屏幕