反应原生图像活化器
ưμ㼯A 自3.0.0版本以来,这个库已经从
react-native-image-resizer改为@bam.tech/react-native-image-resizer
设置
原生反应 0.61
从版本开始 3.0.0 此软件包支持框外的新架构( Turbo 模块) .
亦有与旧相相相相相.
yarn add @bam.tech/react-native-image-resizer
cd ios && pod install
原生反应 0.60
yarn add [email protected]
cd ios && pod install
机器人
注意: 在最新版本的 React Industrial 上, 您可能在 Android 上的 Gradle 构建过程中出现错误(com.android.dex.DexException: Multiple dex files define Landroid/support/v7/appcompat/R$anim) (中文(简体) ). 运行 cd android && ./gradlew clean 来解决这个问题.
手动链接
手动链接Android的信息 : 链接
用法实例
import ImageResizer from '@bam.tech/react-native-image-resizer';
ImageResizer.createResizedImage(
path,
maxWidth,
maxHeight,
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.
});
软件样本
一个基本的,样本应用软件在 页:1 example 文件夹它使用模块来调整相机卷的照片大小.
API 密码
createResizedImage(
/**
* uri parameter accepts`path` or `uri`.
* This property has been tested with the output of @bam.tech/react-native-image-picker,
* react-native-vision-camera, @react-native-camera-roll/camera-roll and http link
**/
uri,
maxWidth,
maxHeight,
compressFormat,
quality,
(rotation = 0),
outputPath,
(keepMeta = false),
(options = {})
); // Returns a Promise
承诺以包含以下内容的物体解决: path, (中文(简体) ), uri, (中文(简体) ), name, (中文(简体) ), size (字节), width (像素),和 height 新建文件。 URI可以直接用作 source 一、导 言 <Image> 组件.
| 选项 | 说明 |
|---|---|
| 路径 | 图像文件的路径, 或以“ data: image/ imagetype” 前缀的已编码的 Base64 图像字符串 imagetype 是jpeg还是png. |
| 宽度 | 宽度调整到大小( 见 mode (详细情况) |
| 高度 | 调整大小的高度( 见 mode (详细情况) |
| 压缩格式 | 可以是JPEG,PNG或WEBP(只有机器人). |
| 质量 | 0到100之间的数字。 用于JPEG压缩. |
| 旋转 | 旋转应用到图像上,以度为单位,用于和机器人. 在iOS上,自转被限制(并四舍五入)为90度倍数. |
| 输出Path | 调整图像路径大小 。 如果无效, 调整大小的图像将存储在缓存文件夹中 。 要设置输出Path, 必须确保也添加旋转选项( 如果不需要旋转, 请设置为 0 ) . |
| 保留梅塔 | 若为 true,将尝试保存所有文件元数据/exif信息,但方向值除外,因为再调整大小也会对原始图像进行旋转修正。 默认为 false,这意味着所有元数据都丢失。 说明: 这只能是 true 页:1 JPEG 从文件系统(不是Web)上载的图像. |
| 选项. 模式 | 类似 反应- 内生图像的缩放: 任意 contain (默认), cover,或 stretch。 。 。 . contain 将符合内部图像 width 财务报告和审定财务报表 height保持其比例. cover 保存宽度比,并确保图像至少 width 宽或 height 高个子. stretch 将图像大小调整到 width 财务报告和审定财务报表 height。 。 。 . |
| 选项。只向下 | 若为 true,永远不会放大图像,只会让它变小. |
限制
- 使用时
@react-native-camera-roll/camera-roll启用新架构的库无法工作。如果您尝试显示图像与uri使用<Image />您将出现以下错误:No suitable image URL loader found for ph://...。这个错误来自反导ImageLoader,这是我们现在使用的。 欢迎帮助/PR解决这个问题。 在此之前,我们建议使用react-native-image-picker。 。 。 . - 图像 EXIF 方向仅在Android上正确处理,但尚未在 IOS 上处理 402号。 。 。 .
关于巴姆
我们是一个百人公司 开发和设计多平台应用 原生反应 使用 Lean & Agile 方法。 要了解更多适合你需要的解决方案,请随意联系 电子邮件 或通过或 联系表单来啊!
我们总是会很高兴地回答你