forked from floraachy/ImageKnife
commit
89fcb3a5d3
|
@ -207,35 +207,11 @@ struct IndexFunctionDemo {
|
|||
|
||||
|
||||
|
||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
|
||||
Button("大量照片和重复数据")
|
||||
.onClick(() => {
|
||||
console.log("pages/manyPhotoShowPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/manyPhotoShowPage" });
|
||||
}).margin({ top: 15 })
|
||||
Button("图片加载暂停和恢复")
|
||||
.onClick(() => {
|
||||
console.log("pages/manyPhotoShowPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/photosPausedResumedPage" });
|
||||
}).margin({ top: 15 })
|
||||
Button("部分url测试")
|
||||
.onClick(() => {
|
||||
console.log("pages/tempUrlTestPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/tempUrlTestPage" });
|
||||
}).margin({ top: 15 })
|
||||
Button("测试drawFactory")
|
||||
.onClick(() => {
|
||||
console.log("pages/drawFactoryTestPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/drawFactoryTestPage" });
|
||||
}).margin({ top: 15 })
|
||||
|
||||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
|
||||
Button("大量照片和重复数据")
|
||||
Button("大量照片")
|
||||
.onClick(() => {
|
||||
console.log("pages/manyPhotoShowPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/manyPhotoShowPage" });
|
||||
|
@ -254,12 +230,12 @@ struct IndexFunctionDemo {
|
|||
}.width('100%').height(60).backgroundColor(Color.Pink)
|
||||
|
||||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("图片加载暂停和恢复")
|
||||
Button("图片暂停和恢复")
|
||||
.onClick(() => {
|
||||
console.log("pages/photosPausedResumedPage 页面跳转")
|
||||
router.pushUrl({ url: "pages/photosPausedResumedPage" });
|
||||
}).margin({ top: 15 })
|
||||
Button("List滑动时暂停图片加载,滑动结束恢复图片加载")
|
||||
Button("List滑动暂停和恢复")
|
||||
.onClick(() => {
|
||||
console.log("pages/photosPausedResumedPage2 页面跳转")
|
||||
router.pushUrl({ url: "pages/photosPausedResumedPage2" });
|
||||
|
|
|
@ -16,6 +16,8 @@ import {AsyncTransform} from '../transform/AsyncTransform'
|
|||
import image from '@ohos.multimedia.image'
|
||||
import { Size } from '../../imageknife/RequestOption'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { Constants } from '../constants/Constants'
|
||||
|
||||
export class TransformUtils {
|
||||
static centerCrop(buf: ArrayBuffer, outWidth: number, outHeihgt: number,
|
||||
callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
|
@ -69,16 +71,21 @@ export class TransformUtils {
|
|||
}
|
||||
|
||||
static centerInside(buf: ArrayBuffer, outWidth: number, outHeihgt: number,
|
||||
callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
callback?: AsyncTransform<PixelMap>) {
|
||||
let imageSource: image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p: image.ImageInfo) => {
|
||||
let pw = p.size.width;
|
||||
let ph = p.size.height;
|
||||
if (pw <= outWidth && ph <= outHeihgt) {
|
||||
let promise:Promise<PixelMap> = imageSource.createPixelMap()
|
||||
imageSource.createPixelMap()
|
||||
.then(p => {
|
||||
callback?.asyncTransform('', p);
|
||||
imageSource.release()
|
||||
callback?.asyncTransform('', promise);
|
||||
}).catch((e: BusinessError) => {
|
||||
callback?.asyncTransform(Constants.PROJECT_TAG + ';CenterInside error:' + e, null);
|
||||
imageSource.release()
|
||||
})
|
||||
} else {
|
||||
TransformUtils.fitCenter(buf, outWidth, outHeihgt, callback);
|
||||
}
|
||||
|
@ -90,7 +97,7 @@ export class TransformUtils {
|
|||
}
|
||||
|
||||
static fitCenter(buf: ArrayBuffer, outWidth: number, outHeihgt: number
|
||||
, callback?: AsyncTransform<Promise<PixelMap>>) {
|
||||
, callback?: AsyncTransform<PixelMap>) {
|
||||
let imageSource: image.ImageSource = image.createImageSource(buf);
|
||||
imageSource.getImageInfo()
|
||||
.then((p: image.ImageInfo) => {
|
||||
|
@ -115,10 +122,16 @@ export class TransformUtils {
|
|||
rotate: 0,
|
||||
desiredSize: { width: targetWidth, height: targetHeight }
|
||||
}
|
||||
if (callback) {
|
||||
let promise:Promise<PixelMap> = imageSource.createPixelMap(options);
|
||||
if (callback != undefined) {
|
||||
imageSource.createPixelMap(options)
|
||||
.then(p => {
|
||||
callback?.asyncTransform('', p);
|
||||
imageSource.release();
|
||||
callback.asyncTransform('', promise);
|
||||
})
|
||||
.catch((e: BusinessError) => {
|
||||
callback?.asyncTransform(Constants.PROJECT_TAG + ';FitCenter error:' + e, null);
|
||||
imageSource.release();
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((e: BusinessError) => {
|
||||
|
|
|
@ -31,12 +31,6 @@ export class CenterInside implements BaseTransform<PixelMap> {
|
|||
}
|
||||
return;
|
||||
}
|
||||
TransformUtils.centerInside(buf, request.size.width, request.size.height, {asyncTransform:(error:BusinessError|string, data:Promise<PixelMap>|null) => {
|
||||
data?.then(p => {
|
||||
func?.asyncTransform('', p);
|
||||
}).catch((e:BusinessError) => {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';CenterInside error:' + e, null);
|
||||
})
|
||||
}})
|
||||
TransformUtils.centerInside(buf, request.size.width, request.size.height, func)
|
||||
}
|
||||
}
|
|
@ -31,12 +31,6 @@ export class FitCenter implements BaseTransform<PixelMap> {
|
|||
}
|
||||
return;
|
||||
}
|
||||
TransformUtils.fitCenter(buf, request.size.width, request.size.height, {asyncTransform:(error:BusinessError|string, data:Promise<PixelMap>|null) => {
|
||||
data?.then(p => {
|
||||
func?.asyncTransform('', p);
|
||||
}).catch((e:BusinessError) => {
|
||||
func?.asyncTransform(Constants.PROJECT_TAG + ';FitCenter error:' + e, null);
|
||||
})
|
||||
}})
|
||||
TransformUtils.fitCenter(buf, request.size.width, request.size.height, func)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue