Skip to content

图片无法改变大小 #8

Open
@hyfjjjj

Description

@hyfjjjj

描述 / Description

随意缩放任何一个图片都能复现这个bug:

import ImageResizer from '@bam.tech/react-native-image-resizer';
ImageResizer.createResizedImage(...)

返回值里面width和height是正确的,但是生成的图片还是老的大小,错误原因也很明显,错误代码文件为:harmony/image_resizer/src/main/ets/ImageResizerModule.ts,如下:

// 目前在 140,141行
let xScale = Math.round(this.finalWidth / oldWidth);
let yScale = Math.round(this.finalHeight / oldHeight);

Math.round导致的,这个函数会把缩放倍数变成整数,很简单的错误。当缩放很小时, xScale和yScale必然为0,缩放api会不执行。当缩放接近时,会被Math.round变成1,也就是不缩放。只有放大1.5倍以上时,才会变成放大2,3,4...整数倍。

把Math.round删掉就可以了。

复现步骤 / Steps to reproduce

No response

库版本 / Library version

3.0.9-0.0.2

React Native OpenHarmony version

0.72.46

构建类型 / Build type

None

设备 / Device

None

设备版本 / Device model

No response

已悉知 / Acknowledgements

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions