Compare commits

..

No commits in common. "a1e8e0b15fd7033d72a71f9523ef148549b11ba3" and "f709bd3f012c5ed7c868a1a4cf3524c6074d35b1" have entirely different histories.

6 changed files with 36 additions and 38 deletions

View File

@ -1,7 +1,3 @@
## 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,47 +12,49 @@
* 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 { ImageKnifeComponent } from '@ohos/libraryimageknife'; import {
import { display } from '@kit.ArkUI'; ImageKnifeComponent,
ImageKnifeData,
ImageKnifeRequest, LogUtil
} from '@ohos/libraryimageknife';
@Entry @Entry
@Component @Component
struct AutoImageFit { struct AutoImageFit {
@State imageWidth: number = 200; @State width1: Length = '100%'
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') Image('https://contentcenter-drcn.dbankcdn.cn/pub_1/DevEcoSpace_1_900_9/56/v3/8MdhfSsCSMKj4sA6okUWrg/5uBx56tLTUO3RYQl-E5JiQ.jpg').width('100%').objectFit(ImageFit.Auto)
.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(100, 100, 0)); transformations.push(new CropTransformation(25, 25, 0));
} }
if (this.isCropCenter) { if (this.isCropCenter) {
transformations.push(new CropTransformation(100, 100, 1)); transformations.push(new CropTransformation(25, 25, 1));
} }
if (this.isCropBottom) { if (this.isCropBottom) {
transformations.push(new CropTransformation(100, 100, 2)); transformations.push(new CropTransformation(25, 25, 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.1-rc.0", "version": "3.2.0",
"dependencies": { "dependencies": {
"@ohos/gpu_transform": "^1.0.2" "@ohos/gpu_transform": "^1.0.2"
}, },

View File

@ -192,6 +192,7 @@ 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,12 +56,11 @@ 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(scaledHeight)); let top: number = Math.abs(this.getTop(pixelMapHeight));
toTransform.scaleSync(scale,scale)
let region: image.Region = { let region: image.Region = {
size: { size: {
width: this.mWidth, width: scaledWidth > pixelMapWidth ? pixelMapWidth : scaledWidth,
height: this.mHeight height: scaledHeight > pixelMapHeight ? pixelMapHeight : scaledHeight
}, },
x: left < 0 ? 0 : left, x: left < 0 ? 0 : left,
y: top < 0 ? 0 : top y: top < 0 ? 0 : top