Compare commits

...

3 Commits

Author SHA1 Message Date
openharmony_ci a1e8e0b15f
!452 修复自定义矩形裁剪异常、清除文件缓存接口导致文件缓存失效
Merge pull request !452 from zgf/master
2025-01-13 07:40:45 +00:00
zgf 1615da7b7c 修复自定义矩形裁剪异常、清除文件缓存接口导致文件缓存失效
Signed-off-by: zgf <zenggaofeng2@h-partners.com>
2025-01-13 14:49:46 +08:00
madixin 3378d36046 优化ImageFit.Auto的demo,使用滚动条调整宽度,体现高度的自适应
Signed-off-by: madixin <42690727@qq.com>
2025-01-12 11:57:05 +08:00
6 changed files with 38 additions and 36 deletions

View File

@ -1,3 +1,7 @@
## 3.2.1-rc.0
- Fix bug: CropTransformation is used to crop the original image
- Fix bug: After calling the clear all file cache interfaces, the file cache becomes invalid
## 3.2.0 ## 3.2.0
- When successfully requesting the network, return the httpcode as well - When successfully requesting the network, return the httpcode as well
- Fix bug: Network error code httpCode returns no data - Fix bug: Network error code httpCode returns no data

View File

@ -12,49 +12,47 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import { import { ImageKnifeComponent } from '@ohos/libraryimageknife';
ImageKnifeComponent, import { display } from '@kit.ArkUI';
ImageKnifeData,
ImageKnifeRequest, LogUtil
} from '@ohos/libraryimageknife';
@Entry @Entry
@Component @Component
struct AutoImageFit { struct AutoImageFit {
@State width1: Length = '100%' @State imageWidth: number = 200;
private maxWidth: number = px2vp(display.getDefaultDisplaySync().width);
build() { build() {
Scroll() {
Column() {
this.Slider()
Column() { Column() {
Button($r('app.string.adjust_size')).onClick(() => {
if (this.width1.toString() == '100%') {
this.width1 = '60%'
} else {
this.width1 = '100%'
}
}).width('100%')
Text('Image') Text('Image')
Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg').width('100%').objectFit(ImageFit.Auto) Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg')
.width('100%')
.objectFit(ImageFit.Auto)
Text('ImageKnife') Text('ImageKnife')
ImageKnifeComponent({ ImageKnifeComponent({
imageKnifeOption: { imageKnifeOption: {
loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg', loadSrc: 'https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg',
objectFit: ImageFit.Auto, objectFit: ImageFit.Auto,
onLoadListener: {
onLoadStart: (request?: ImageKnifeRequest) => {
LogUtil.info('onLoadStart')
},
onLoadSuccess: (data: string | PixelMap | undefined, imageKnifeData: ImageKnifeData,
request?: ImageKnifeRequest) => {
LogUtil.info('onLoadSuccess')
}
}
} }
}).width('100%') }).width('100%')
}.width(this.imageWidth).border({ width: 1 })
}.width(this.width1).border({ width: 1 })
} }
} }
}
@Builder
Slider() {
Slider({
value: this.imageWidth,
min: 100,
max: this.maxWidth,
style: SliderStyle.OutSet
})
.blockColor(Color.White)
.width('100%')
.onChange((value: number) => {
this.imageWidth = value;
})
}
}

View File

@ -398,13 +398,13 @@ struct ImageTransformation {
transformations.push(new CropSquareTransformation()); transformations.push(new CropSquareTransformation());
} }
if (this.isCropTop) { if (this.isCropTop) {
transformations.push(new CropTransformation(25, 25, 0)); transformations.push(new CropTransformation(100, 100, 0));
} }
if (this.isCropCenter) { if (this.isCropCenter) {
transformations.push(new CropTransformation(25, 25, 1)); transformations.push(new CropTransformation(100, 100, 1));
} }
if (this.isCropBottom) { if (this.isCropBottom) {
transformations.push(new CropTransformation(25, 25, 2)); transformations.push(new CropTransformation(100, 100, 2));
} }
if (this.isSepia) { if (this.isSepia) {
transformations.push(new SepiaTransformation()); transformations.push(new SepiaTransformation());

View File

@ -14,7 +14,7 @@
"main": "index.ets", "main": "index.ets",
"repository": "https://gitee.com/openharmony-tpc/ImageKnife", "repository": "https://gitee.com/openharmony-tpc/ImageKnife",
"type": "module", "type": "module",
"version": "3.2.0", "version": "3.2.1-rc.0",
"dependencies": { "dependencies": {
"@ohos/gpu_transform": "^1.0.2" "@ohos/gpu_transform": "^1.0.2"
}, },

View File

@ -192,7 +192,6 @@ export class FileCache {
if (!this.isInited) { if (!this.isInited) {
return return
} }
this.isInited = false
this.lruCache.clear() this.lruCache.clear()
this.currentMemory = 0; this.currentMemory = 0;

View File

@ -56,11 +56,12 @@ export class CropTransformation extends PixelMapTransformation {
let scaledWidth: number = scale * pixelMapWidth; let scaledWidth: number = scale * pixelMapWidth;
let scaledHeight: number = scale * pixelMapHeight; let scaledHeight: number = scale * pixelMapHeight;
let left: number = (this.mWidth - scaledWidth) / 2; let left: number = (this.mWidth - scaledWidth) / 2;
let top: number = Math.abs(this.getTop(pixelMapHeight)); let top: number = Math.abs(this.getTop(scaledHeight));
toTransform.scaleSync(scale,scale)
let region: image.Region = { let region: image.Region = {
size: { size: {
width: scaledWidth > pixelMapWidth ? pixelMapWidth : scaledWidth, width: this.mWidth,
height: scaledHeight > pixelMapHeight ? pixelMapHeight : scaledHeight height: this.mHeight
}, },
x: left < 0 ? 0 : left, x: left < 0 ? 0 : left,
y: top < 0 ? 0 : top y: top < 0 ? 0 : top