forked from floraachy/ImageKnife
1.ArkTs整改17 整改entry->pages
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
92824c62c2
commit
cfd31304d4
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ImageKnifeComponent, ImageKnifeOption,NONE } from '@ohos/imageknife'
|
||||
import { ImageKnifeComponent, ImageKnifeOption,NONE,DiskStrategy } from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -39,13 +39,14 @@ struct OptionTestPage {
|
|||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("加载")
|
||||
.onClick(() => {
|
||||
let setting:DiskStrategy = new NONE();
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
onlyRetrieveFromCache: false,
|
||||
isCacheable: false,
|
||||
strategy: new NONE()
|
||||
strategy: setting
|
||||
}
|
||||
}).margin({ top: 5, left: 3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 }).width(300).height(300)
|
||||
|
@ -55,13 +56,14 @@ struct OptionTestPage {
|
|||
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
Button("加载")
|
||||
.onClick(() => {
|
||||
let setting2:DiskStrategy = new NONE();
|
||||
this.imageKnifeOption2 = {
|
||||
loadSrc: 'https://img-blog.csdn.net/20140514114029140',
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
onlyRetrieveFromCache: true,
|
||||
isCacheable: true,
|
||||
strategy: new NONE()
|
||||
strategy: setting2
|
||||
}
|
||||
}).margin({ top: 5, left: 3 })
|
||||
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }).width(300).height(300)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import { FileUtils, ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import { BusinessError } from '@ohos.base'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -25,7 +26,7 @@ struct basicTestFileIOPage {
|
|||
@State imageHint: string = ''
|
||||
@State imageFile: string = '文字提醒'
|
||||
@State imageRes: Resource = $r('app.media.pngSample')
|
||||
@State imagePixelMap: PixelMap = undefined
|
||||
@State imagePixelMap?: PixelMap = undefined
|
||||
@State normalPixelMap: boolean = false;
|
||||
@State normalResource: boolean = false;
|
||||
|
||||
|
@ -89,8 +90,8 @@ struct basicTestFileIOPage {
|
|||
this.imageFile = 'file://' + this.appFilePath + '/Folder1/jpgSample.gif'
|
||||
console.log('Folder1 imaeFile =' + this.imageFile)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err as BusinessError));
|
||||
})
|
||||
})
|
||||
Button('copy:Folder1至Folder2, 验证copyFileSync')
|
||||
|
|
|
@ -19,11 +19,11 @@ import resourceManager from '@ohos.resourceManager';
|
|||
import { Base64 } from '@ohos/imageknife'
|
||||
import { ParseImageUtil } from '@ohos/imageknife'
|
||||
import { ImageKnifeGlobal } from '@ohos/imageknife'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct BasicTestMediaImage {
|
||||
@State imagePixelMap: PixelMap = undefined;
|
||||
@State imagePixelMap?: PixelMap = undefined;
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
|
@ -38,10 +38,10 @@ struct BasicTestMediaImage {
|
|||
let parseImageUtil = new ParseImageUtil();
|
||||
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
|
||||
this.imagePixelMap = pxielmap;
|
||||
}, (err) => {
|
||||
}, (err:BusinessError|string|undefined) => {
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
}).margin({ left: 15 }).backgroundColor(Color.Blue)
|
||||
|
@ -54,10 +54,10 @@ struct BasicTestMediaImage {
|
|||
let parseImageUtil = new ParseImageUtil();
|
||||
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
|
||||
this.imagePixelMap = pxielmap;
|
||||
}, (err) => {
|
||||
},(err:BusinessError|string|undefined) => {
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
}).margin({ left: 15 }).backgroundColor(Color.Blue)
|
||||
|
@ -70,10 +70,10 @@ struct BasicTestMediaImage {
|
|||
let parseImageUtil = new ParseImageUtil();
|
||||
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
|
||||
this.imagePixelMap = pxielmap;
|
||||
}, (err) => {
|
||||
}, (err:BusinessError|string|undefined) => {
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
}).margin({ left: 15 }).backgroundColor(Color.Blue)
|
||||
|
@ -86,10 +86,10 @@ struct BasicTestMediaImage {
|
|||
let parseImageUtil = new ParseImageUtil();
|
||||
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
|
||||
this.imagePixelMap = pxielmap;
|
||||
}, (err) => {
|
||||
}, (err:BusinessError|string|undefined) => {
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
}).margin({ left: 15 }).backgroundColor(Color.Blue)
|
||||
|
@ -102,10 +102,10 @@ struct BasicTestMediaImage {
|
|||
let parseImageUtil = new ParseImageUtil();
|
||||
parseImageUtil.parseImage(arrayBuffer, (pxielmap) => {
|
||||
this.imagePixelMap = pxielmap;
|
||||
}, (err) => {
|
||||
}, (err:BusinessError|string|undefined) => {
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestMediaImage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
}).margin({ left: 15 }).backgroundColor(Color.Blue)
|
||||
|
|
|
@ -18,7 +18,7 @@ import {FileTypeUtil} from '@ohos/imageknife'
|
|||
import resourceManager from '@ohos.resourceManager';
|
||||
import {Base64} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct BasicTestResourceManagerPage {
|
||||
|
@ -42,7 +42,7 @@ struct BasicTestResourceManagerPage {
|
|||
let fileType = filetypeUtil.getFileType(arrayBuffer);
|
||||
this.fileTypeStr = fileType;
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
})
|
||||
|
@ -55,7 +55,7 @@ struct BasicTestResourceManagerPage {
|
|||
.then(data => {
|
||||
console.log('ParseResClientBase64 - 本地加载资源 解析后数据data')
|
||||
let matchReg = ';base64,';
|
||||
var firstIndex = data.indexOf(matchReg);
|
||||
let firstIndex = data.indexOf(matchReg);
|
||||
data = data.substring(firstIndex + matchReg.length, data.length)
|
||||
console.log('ParseResClientBase64 - 本地加载资源 解析后数据剔除非必要数据后data= ' + data)
|
||||
let arrayBuffer = Base64.getInstance()
|
||||
|
@ -64,7 +64,7 @@ struct BasicTestResourceManagerPage {
|
|||
let fileType = filetypeUtil.getFileType(arrayBuffer);
|
||||
this.fileTypeStr = fileType;
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
})
|
||||
|
|
|
@ -20,8 +20,8 @@ import {ImageKnifeGlobal} from '@ohos/imageknife'
|
|||
@Entry
|
||||
@Component
|
||||
struct CompressPage {
|
||||
@State mRPixelMap: PixelMap = undefined;
|
||||
@State mFPixelMap: PixelMap = undefined;
|
||||
@State mRPixelMap?: PixelMap = undefined;
|
||||
@State mFPixelMap?: PixelMap = undefined;
|
||||
@State mResultText: string= "压缩回调结果"
|
||||
@State mResultPath: string= "压缩路径:"
|
||||
@State mAsyncPath: string= ""
|
||||
|
@ -91,7 +91,7 @@ struct CompressPage {
|
|||
}.width('100%').height('100%');
|
||||
}
|
||||
private compressAsyncRecource() {
|
||||
var data = new Array<Resource>();
|
||||
let data = new Array<Resource>();
|
||||
data.push($r('app.media.jpgSample'))
|
||||
|
||||
console.info("asasd start compress")
|
||||
|
@ -100,7 +100,7 @@ struct CompressPage {
|
|||
.load(data)
|
||||
.ignoreBy(100)
|
||||
.get()
|
||||
.then((path)=>{
|
||||
.then((path:string)=>{
|
||||
this.mAsyncPathHint = path;
|
||||
this.mAsyncPath='file://' + path;
|
||||
})
|
||||
|
@ -108,30 +108,31 @@ struct CompressPage {
|
|||
console.info("asasd start compress end")
|
||||
}
|
||||
private cropressRecource() {
|
||||
var data = new Array<Resource>();
|
||||
let data = new Array<Resource>();
|
||||
data.push($r('app.media.jpgSample'))
|
||||
var rename: OnRenameListener = {
|
||||
let rename: OnRenameListener = {
|
||||
reName() {
|
||||
return "test_1.jpg";
|
||||
}
|
||||
}
|
||||
var that = this;
|
||||
var listener: OnCompressListener = {
|
||||
start() {
|
||||
that.mResultText = "start"
|
||||
|
||||
let listener: OnCompressListener = {
|
||||
start:()=>{
|
||||
this.mResultText = "start"
|
||||
console.info("asasd start")
|
||||
},
|
||||
onScuccess(p: PixelMap, path: string) {
|
||||
let pack = undefined;
|
||||
pack = p;
|
||||
that.mRPixelMap = pack;
|
||||
console.info("asasd success path:" + this.mRPixelMap)
|
||||
that.mResultText = "success";
|
||||
that.mResultPath = path;
|
||||
onScuccess:(p: PixelMap | null | undefined, path: string)=> {
|
||||
if(p!=null && p!=undefined) {
|
||||
let pack = p;
|
||||
this.mRPixelMap = pack as PixelMap;
|
||||
console.info("asasd success path:" + this.mRPixelMap)
|
||||
this.mResultText = "success";
|
||||
this.mResultPath = path;
|
||||
}
|
||||
},
|
||||
onError(s: string) {
|
||||
onError:(s: string)=>{
|
||||
console.info("asasd onError:" + s)
|
||||
that.mResultText = "fail";
|
||||
this.mResultText = "fail";
|
||||
}
|
||||
}
|
||||
console.info("asasd start compress")
|
||||
|
|
|
@ -17,8 +17,7 @@ import { CropImage } from '@ohos/imageknife'
|
|||
import { CropOptions } from '@ohos/imageknife'
|
||||
import { Crop } from '@ohos/imageknife'
|
||||
import { RecourseProvider } from '@ohos/imageknife'
|
||||
import { PixelMapCropNameSpace } from '@ohos/imageknife'
|
||||
import { PixelMapCrop } from '@ohos/imageknife'
|
||||
import { PixelMapCrop,Options } from '@ohos/imageknife'
|
||||
import { CropCallback } from '@ohos/imageknife'
|
||||
import { FileUtils } from '@ohos/imageknife'
|
||||
import { ImageKnifeGlobal } from '@ohos/imageknife'
|
||||
|
@ -45,23 +44,22 @@ export struct CropImagePage2 {
|
|||
.onClick(() => {
|
||||
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
|
||||
.getMediaContent($r('app.media.bmpSample').id)
|
||||
.then(data => {
|
||||
.then((data:Uint8Array) => {
|
||||
let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
let optionx = new Options();
|
||||
optionx.setWidth(800)
|
||||
.setHeight(800)
|
||||
.setCropFunction((err:BusinessError, pixelmap:PixelMap, sx:number, sy:number) => {
|
||||
.setCropFunction((err:BusinessError|string, pixelmap:PixelMap|null, sx:number, sy:number) => {
|
||||
console.log('PMC setCropFunction callback')
|
||||
if (err) {
|
||||
console.error('PMC crop err =' + err)
|
||||
} else {
|
||||
|
||||
this.width1 = sx * px2vp(1);
|
||||
this.height1 = sy * px2vp(1);
|
||||
this.canvasContext.drawImage(pixelmap,0,0,this.width1,this.height1)
|
||||
if(pixelmap != null) {
|
||||
this.canvasContext.drawImage(pixelmap, 0, 0, this.width1, this.height1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
optionx.loadBuffer(arrayBuffer, () => {
|
||||
this.options1 = optionx;
|
||||
|
@ -90,10 +88,14 @@ export struct CropImagePage2 {
|
|||
})
|
||||
.scale({ x: this._scale, y: this._scale, z: 1.0 })
|
||||
.gesture(GestureGroup(GestureMode.Parallel,
|
||||
RotationGesture({ fingers: 2 }).onActionUpdate(event => {
|
||||
this._rotate = event.angle;
|
||||
}), PinchGesture({ fingers: 2 }).onActionUpdate(event => {
|
||||
this._scale = event.scale;
|
||||
RotationGesture({ fingers: 2 }).onActionUpdate((event?: GestureEvent) => {
|
||||
if(event != undefined) {
|
||||
this._rotate = event.angle;
|
||||
}
|
||||
}), PinchGesture({ fingers: 2 }).onActionUpdate((event?: GestureEvent) => {
|
||||
if(event != undefined) {
|
||||
this._scale = event.scale;
|
||||
}
|
||||
})))
|
||||
}
|
||||
.backgroundColor(Color.Brown)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||
import { ImageKnifeComponent, ImageKnifeOption, } from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -26,7 +26,7 @@ struct DataShareUriLoadPage {
|
|||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed')
|
||||
};
|
||||
private globalGifWorker: any = undefined
|
||||
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
|
@ -42,7 +42,7 @@ struct DataShareUriLoadPage {
|
|||
let fileKeyObj = mediaLibrary.FileKey;
|
||||
let imageType = mediaLibrary.MediaType.IMAGE;
|
||||
// 创建文件获取选项,此处参数为获取image类型的文件资源
|
||||
let imagesFetchOp = {
|
||||
let imagesFetchOp:mediaLibrary.MediaFetchOptions = {
|
||||
selections: fileKeyObj.MEDIA_TYPE + '= ?',
|
||||
selectionArgs: [imageType.toString()],
|
||||
};
|
||||
|
|
|
@ -14,14 +14,15 @@
|
|||
*/
|
||||
import {GIFParseImpl} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker';
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import { BusinessError } from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct gifTestCasePage {
|
||||
|
||||
@State pixels:PixelMap = undefined
|
||||
private globalGifWorker = undefined;
|
||||
@State pixels?:PixelMap = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined;
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
|
@ -44,7 +45,7 @@ struct gifTestCasePage {
|
|||
}
|
||||
},undefined,true)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
|
||||
|
@ -70,7 +71,7 @@ struct gifTestCasePage {
|
|||
}
|
||||
},local_worker)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
|
||||
|
@ -93,7 +94,7 @@ struct gifTestCasePage {
|
|||
}
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ import worker from '@ohos.worker';
|
|||
@Entry
|
||||
@Component
|
||||
struct IndexFunctionDemo {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.icon'),
|
||||
|
|
|
@ -33,10 +33,13 @@ struct ManyPhotoShowPage {
|
|||
|
||||
Button('设置磁盘存储为50M')
|
||||
.onClick(()=>{
|
||||
let disk:DiskLruCache = (ImageKnifeGlobal.getInstance().getImageKnife()).getDiskMemoryCache();
|
||||
disk.setMaxSize(50*1024*1024)
|
||||
Prompt.showToast({message:"设置成功"})
|
||||
|
||||
if(ImageKnifeGlobal.getInstance().getImageKnife() != undefined) {
|
||||
let disk: DiskLruCache | undefined = (ImageKnifeGlobal.getInstance().getImageKnife())?.getDiskMemoryCache();
|
||||
if(disk != undefined) {
|
||||
disk.setMaxSize(50 * 1024 * 1024)
|
||||
Prompt.showToast({ message: "设置成功" })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
List({ space: 20, scroller: this.elementScroller }) {
|
||||
|
|
|
@ -19,14 +19,14 @@ import { FileUtils,ImageKnifeGlobal } from '@ohos/imageknife'
|
|||
import featureability from '@ohos.ability.featureAbility'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker';
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct PngjTestCasePage {
|
||||
pngSource1: ArrayBuffer = undefined;
|
||||
pngSource2: ArrayBuffer = undefined;
|
||||
pngSource3: ArrayBuffer = undefined;
|
||||
pngSource4: ArrayBuffer = undefined;
|
||||
pngSource1?: ArrayBuffer = undefined;
|
||||
pngSource2?: ArrayBuffer = undefined;
|
||||
pngSource3?: ArrayBuffer = undefined;
|
||||
pngSource4?: ArrayBuffer = undefined;
|
||||
pngdecodeRun1: boolean = false;
|
||||
pngdecodeRun2: boolean = false;
|
||||
pngdecodeRun3: boolean = false;
|
||||
|
@ -60,14 +60,14 @@ struct PngjTestCasePage {
|
|||
this.pngSource1 = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
this.hint7 = '获取buffer成功,可以测试'
|
||||
})
|
||||
.catch(err => {
|
||||
.catch( (err:BusinessError) => {
|
||||
console.log('点击获取Png图片buffer err=' + err)
|
||||
})
|
||||
})
|
||||
Button('测试readPng')
|
||||
.onClick(() => {
|
||||
|
||||
if (this.pngSource1) {
|
||||
if (this.pngSource1!=undefined) {
|
||||
if (!this.pngdecodeRun1) {
|
||||
this.pngdecodeRun1 = true;
|
||||
let pngj = new Pngj();
|
||||
|
@ -103,14 +103,14 @@ struct PngjTestCasePage {
|
|||
this.pngSource2 = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
this.hint8 = '获取buffer成功,可以测试'
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('点击获取Png图片buffer err=' + err)
|
||||
})
|
||||
})
|
||||
Button('readPngAsync')
|
||||
.onClick(() => {
|
||||
|
||||
if (this.pngSource2) {
|
||||
if (this.pngSource2!=undefined) {
|
||||
if (!this.pngdecodeRun2) {
|
||||
this.pngdecodeRun2 = true;
|
||||
let pngj = new Pngj();
|
||||
|
@ -118,7 +118,7 @@ struct PngjTestCasePage {
|
|||
type: 'classic',
|
||||
name: 'readPngImageAsync'
|
||||
})
|
||||
pngj.readPngImageAsync(png_worker, this.pngSource1, {pngCallback: (sender, value) => {
|
||||
pngj.readPngImageAsync(png_worker, this.pngSource2!, {pngCallback: (sender:ArrayBuffer, value:Record<string,Object>) => {
|
||||
this.pngSource1 = sender
|
||||
this.hint2 = 'img with=' + value.width + ' img height=' + value.height
|
||||
+ ' img depth=' + value.depth + ' img ctype=' + value.ctype
|
||||
|
@ -148,14 +148,14 @@ struct PngjTestCasePage {
|
|||
this.pngSource3 = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
this.hint9 = '获取buffer成功,可以测试'
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('点击获取Png图片buffer err=' + err)
|
||||
})
|
||||
})
|
||||
Button('测试writePngWithString')
|
||||
.onClick(() => {
|
||||
|
||||
if (this.pngSource3) {
|
||||
if (this.pngSource3 != undefined) {
|
||||
if (!this.pngdecodeRun3) {
|
||||
this.pngdecodeRun3 = true;
|
||||
let pngj = new Pngj();
|
||||
|
@ -163,7 +163,7 @@ struct PngjTestCasePage {
|
|||
type: 'classic',
|
||||
name: 'writePngWithStringAsync'
|
||||
})
|
||||
pngj.writePngWithStringAsync(png_worker, 'hello world', this.pngSource3, {pngCallback: (sender, value) => {
|
||||
pngj.writePngWithStringAsync(png_worker, 'hello world', this.pngSource3, {pngCallback: (sender:ArrayBuffer, value:ArrayBuffer) => {
|
||||
this.pngSource3 = sender
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
|
@ -198,13 +198,13 @@ struct PngjTestCasePage {
|
|||
this.pngSource4 = FileUtils.getInstance().uint8ArrayToBuffer(data);
|
||||
this.hint10 = '获取buffer成功,可以测试'
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('点击获取Png图片buffer err=' + err)
|
||||
})
|
||||
})
|
||||
Button('writePng')
|
||||
.onClick(()=>{
|
||||
if (this.pngSource4) {
|
||||
if (this.pngSource4 != undefined) {
|
||||
if (!this.pngdecodeRun4) {
|
||||
this.pngdecodeRun4 = true;
|
||||
let pngj = new Pngj();
|
||||
|
@ -212,7 +212,7 @@ struct PngjTestCasePage {
|
|||
type: 'classic',
|
||||
name: 'writePngAsync'
|
||||
})
|
||||
pngj.writePngAsync(png_worker, this.pngSource4,{pngCallback: (sender, value) => {
|
||||
pngj.writePngAsync(png_worker, this.pngSource4,{pngCallback: (sender:ArrayBuffer, value:ArrayBuffer) => {
|
||||
this.pngSource4 = sender
|
||||
FileUtils.getInstance().createFileProcess(
|
||||
this.rootFolder + '/pngj',
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
import {LruCache} from '@ohos/imageknife'
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
function getRandomInt(min:number, max:number):number {
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值
|
||||
|
|
|
@ -14,13 +14,14 @@
|
|||
*/
|
||||
import {SVGParseImpl} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
|
||||
import resourceManager from '@ohos.resourceManager';
|
||||
import {BusinessError} from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct svgTestCasePage {
|
||||
|
||||
@State svgSamplePixelMap:PixelMap = undefined
|
||||
@State svgIconPixelMap:PixelMap = undefined
|
||||
@State svgSamplePixelMap?:PixelMap = undefined
|
||||
@State svgIconPixelMap?:PixelMap = undefined
|
||||
|
||||
build() {
|
||||
Scroll() {
|
||||
|
@ -31,14 +32,14 @@ struct svgTestCasePage {
|
|||
|
||||
((ImageKnifeGlobal.getInstance().getHapContext() as Record<string,Object>).resourceManager as resourceManager.ResourceManager)
|
||||
.getMediaContent($r('app.media.svgSample').id)
|
||||
.then(data => {
|
||||
.then((data:Uint8Array) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源 解析后数据data = ' + data)
|
||||
let svgImpl = new SVGParseImpl();
|
||||
svgImpl.parseSvg(data.buffer).then((pixelmap)=>{
|
||||
this.svgSamplePixelMap = pixelmap;
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
|
||||
|
@ -68,7 +69,7 @@ struct svgTestCasePage {
|
|||
this.svgIconPixelMap = pixelmap;
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err:BusinessError) => {
|
||||
console.log('basicTestFileIOPage - 本地加载资源err' + JSON.stringify(err));
|
||||
})
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import router from '@system.router';
|
||||
|
||||
import {
|
||||
ImageKnifeComponent,
|
||||
ImageKnifeOption,
|
||||
|
@ -20,12 +20,11 @@ import {
|
|||
ImageKnifeDrawFactory,
|
||||
ScaleType
|
||||
} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker';
|
||||
@Entry
|
||||
@Component
|
||||
struct tempUrlTestPage {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.icon'),
|
||||
|
|
|
@ -13,19 +13,20 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {ImageKnifeData} from '@ohos/imageknife'
|
||||
import {AllCacheInfo,IAllCacheInfoCallback} from '@ohos/imageknife'
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {TransformType} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
|
||||
import {BusinessError} from '@ohos.base'
|
||||
@Entry
|
||||
@Component
|
||||
struct TestAllCacheInfoPage {
|
||||
@State nativePixelMap: PixelMap = undefined;
|
||||
@State networkPixelMap: PixelMap = undefined;
|
||||
allCacheInfoCallback1 =(allCacheInfo)=>{
|
||||
@State nativePixelMap?: PixelMap = undefined;
|
||||
@State networkPixelMap?: PixelMap = undefined;
|
||||
allCacheInfoCallback1:IAllCacheInfoCallback ={callback:(allCacheInfo:AllCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback imageknifecomponent1 memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback imageknifecomponent1 resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
|
@ -33,8 +34,8 @@ struct TestAllCacheInfoPage {
|
|||
this.cacheinfo3 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
}
|
||||
allCacheInfoCallback2 =(allCacheInfo)=>{
|
||||
}}
|
||||
allCacheInfoCallback2:IAllCacheInfoCallback ={callback:(allCacheInfo:AllCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback ImageKnifeComponent memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback ImageKnifeComponent resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
|
@ -42,7 +43,7 @@ struct TestAllCacheInfoPage {
|
|||
this.cacheinfo4 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
}
|
||||
}}
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
|
@ -165,12 +166,11 @@ struct TestAllCacheInfoPage {
|
|||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.pngSample'))
|
||||
.setImageViewSize({width:300,height:300})
|
||||
.addListener((err, data) => {
|
||||
let pack = undefined;
|
||||
pack = data.drawPixelMap.imagePixelMap as PixelMap;;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
let pack = data.drawPixelMap?.imagePixelMap as PixelMap;;
|
||||
this.nativePixelMap = pack;
|
||||
return false;
|
||||
}).addAllCacheInfoCallback((allCacheInfo)=>{
|
||||
}}).addAllCacheInfoCallback({callback:(allCacheInfo:AllCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
|
@ -178,20 +178,19 @@ struct TestAllCacheInfoPage {
|
|||
this.cacheinfo1 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
})
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
}})
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
private testAllCacheInfoNetwork() {
|
||||
let ImageKnifeOption = new RequestOption();
|
||||
ImageKnifeOption.load("https://hbimg.huabanimg.com/0ef60041445edcfd6b38d20e19024b2cd9281dcc3525a4-Vy8fYO_fw658/format/webp")
|
||||
.addListener((err, data) => {
|
||||
let pack = undefined;
|
||||
pack = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
let pack = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.networkPixelMap = pack;
|
||||
console.log("imageknife2 图片2 赋值!")
|
||||
return false;
|
||||
}).addAllCacheInfoCallback((allCacheInfo)=>{
|
||||
}}).addAllCacheInfoCallback({callback:(allCacheInfo:AllCacheInfo)=>{
|
||||
let info = allCacheInfo as AllCacheInfo;
|
||||
console.log("AllCacheInfoCallback memory ="+JSON.stringify(info.memoryCacheInfo))
|
||||
console.log("AllCacheInfoCallback resource ="+JSON.stringify(info.resourceCacheInfo))
|
||||
|
@ -199,12 +198,12 @@ struct TestAllCacheInfoPage {
|
|||
this.cacheinfo2 = "memory="+JSON.stringify(info.memoryCacheInfo)+
|
||||
"\n resource ="+JSON.stringify(info.resourceCacheInfo)+
|
||||
"\n data ="+JSON.stringify(info.dataCacheInfo)
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({width:300,height:300})
|
||||
.rotateImage(180)
|
||||
ImageKnife.call(ImageKnifeOption);
|
||||
ImageKnife?.call(ImageKnifeOption);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var ImageKnife = (ImageKnifeGlobal.getInstance().getImageKnife())
|
||||
let ImageKnife = (ImageKnifeGlobal.getInstance().getImageKnife())
|
|
@ -16,12 +16,11 @@ import {ImageKnifeComponent} from '@ohos/imageknife'
|
|||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker'
|
||||
@Entry
|
||||
@Component
|
||||
struct TestGifDontAnimatePage {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
|
|
|
@ -23,8 +23,8 @@ struct TestGifLoadWithWorkerPage {
|
|||
@State options: ImageKnifeOption = {
|
||||
loadSrc: $r('app.media.icon')
|
||||
}
|
||||
private my_worker: worker.ThreadWorker;
|
||||
private my_gif_worker: worker.ThreadWorker;
|
||||
private my_worker?: worker.ThreadWorker = undefined;
|
||||
private my_gif_worker?: worker.ThreadWorker = undefined;
|
||||
|
||||
/**
|
||||
* 界面进入时回调
|
||||
|
@ -86,7 +86,7 @@ struct TestGifLoadWithWorkerPage {
|
|||
this.my_gif_worker.onmessage = (e: MessageEvents) => {
|
||||
console.log("my_gif_worker.onmessage: " + e.data)
|
||||
}
|
||||
(ImageKnifeGlobal.getInstance().getImageKnife()).setGifWorker(this.my_gif_worker)
|
||||
(ImageKnifeGlobal.getInstance().getImageKnife())?.setGifWorker(this.my_gif_worker)
|
||||
|
||||
//子线程加载gif,不阻塞toast的消失
|
||||
this.options = {
|
||||
|
|
|
@ -22,7 +22,7 @@ import worker from '@ohos.worker'
|
|||
@Component
|
||||
struct TestImageKnifeOptionChangedPage {
|
||||
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
|
|
|
@ -14,9 +14,11 @@
|
|||
*/
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {BaseTransform} from '@ohos/imageknife'
|
||||
import {RotateImageTransformation} from '@ohos/imageknife'
|
||||
import {GrayscaleTransformation} from '@ohos/imageknife'
|
||||
import {SketchFilterTransformation} from '@ohos/imageknife'
|
||||
import image from '@ohos.multimedia.image'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
@ -38,6 +40,7 @@ struct TestImageKnifeOptionChangedPage2 {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button("网络jpg")
|
||||
.onClick(()=>{
|
||||
let rotateTrans:BaseTransform<image.PixelMap> = new RotateImageTransformation(180)
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
|
||||
|
@ -45,7 +48,7 @@ struct TestImageKnifeOptionChangedPage2 {
|
|||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
thumbSizeMultiplier:0.1,
|
||||
transformation:new RotateImageTransformation(180)
|
||||
transformation:rotateTrans
|
||||
};
|
||||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("png")
|
||||
|
|
|
@ -21,10 +21,12 @@ import {GrayscaleTransformation} from '@ohos/imageknife'
|
|||
import {SketchFilterTransformation} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker'
|
||||
import {BaseTransform} from '@ohos/imageknife'
|
||||
import image from '@ohos.multimedia.image'
|
||||
@Entry
|
||||
@Component
|
||||
struct TestImageKnifeOptionChangedPage3 {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
|
@ -42,13 +44,14 @@ struct TestImageKnifeOptionChangedPage3 {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button("本地jpg")
|
||||
.onClick(()=>{
|
||||
let rotateTrans:BaseTransform<image.PixelMap> = new RotateImageTransformation(180)
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
mainScaleType: ScaleType.FIT_CENTER,
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
thumbSizeMultiplier:0.1,
|
||||
transformation:new RotateImageTransformation(180),
|
||||
transformation:rotateTrans,
|
||||
};
|
||||
animateTo({
|
||||
duration: 500,
|
||||
|
@ -66,13 +69,15 @@ struct TestImageKnifeOptionChangedPage3 {
|
|||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("本地png")
|
||||
.onClick(()=>{
|
||||
|
||||
let rotateTrans:BaseTransform<image.PixelMap> = new RotateImageTransformation(180)
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: $r('app.media.pngSample'),
|
||||
mainScaleType: ScaleType.FIT_CENTER,
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
thumbSizeMultiplier:0.1,
|
||||
transformation:new RotateImageTransformation(180),
|
||||
transformation:rotateTrans,
|
||||
};
|
||||
animateTo({
|
||||
duration: 500,
|
||||
|
@ -142,13 +147,14 @@ struct TestImageKnifeOptionChangedPage3 {
|
|||
Flex({direction:FlexDirection.Row}){
|
||||
Button("网络jpg")
|
||||
.onClick(()=>{
|
||||
let rotateTrans:BaseTransform<image.PixelMap> = new RotateImageTransformation(180)
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
displayProgress:true,
|
||||
thumbSizeMultiplier:0.1,
|
||||
transformation:new RotateImageTransformation(180)
|
||||
transformation:rotateTrans
|
||||
};
|
||||
}).margin({left:5}).backgroundColor(Color.Blue)
|
||||
Button("网络png")
|
||||
|
|
|
@ -22,23 +22,26 @@ import {
|
|||
ScaleTypeHelper,
|
||||
IDrawLifeCycle,
|
||||
ScaleType,
|
||||
ImageKnifeGlobal
|
||||
ImageKnifeGlobal,
|
||||
BaseTransform
|
||||
} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker';
|
||||
import image from '@ohos.multimedia.image';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestImageKnifeOptionChangedPage4 {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?: worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
|
||||
thumbSizeMultiplier: 0.1,
|
||||
drawLifeCycle:this.createViewLifeCycle()
|
||||
drawLifeCycle: this.createViewLifeCycle()
|
||||
};
|
||||
private mTimerId: number = 0
|
||||
|
||||
|
@ -48,15 +51,16 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
Flex({ direction: FlexDirection.Row }) {
|
||||
Button("网络jpg")
|
||||
.onClick(() => {
|
||||
let rotateTrans: BaseTransform<image.PixelMap> = new RotateImageTransformation(180)
|
||||
this.imageKnifeOption1 = {
|
||||
loadSrc: "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB",
|
||||
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
|
||||
thumbSizeMultiplier: 0.1,
|
||||
transformation: new RotateImageTransformation(180),
|
||||
drawLifeCycle:this.createViewLifeCycle()
|
||||
transformation: rotateTrans,
|
||||
drawLifeCycle: this.createViewLifeCycle()
|
||||
};
|
||||
}).margin({ left: 5 }).backgroundColor(Color.Blue)
|
||||
Button("网络png")
|
||||
|
@ -66,13 +70,14 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
|
||||
thumbSizeMultiplier: 0.1,
|
||||
transformations: [new RotateImageTransformation(180)],
|
||||
drawLifeCycle:this.createViewLifeCycle()
|
||||
drawLifeCycle: this.createViewLifeCycle()
|
||||
};
|
||||
}).margin({ left: 5 }).backgroundColor(Color.Blue)
|
||||
}.margin({ top: 15 })
|
||||
|
||||
Flex({ direction: FlexDirection.Row }) {
|
||||
Button("网络bmp")
|
||||
.onClick(() => {
|
||||
|
@ -81,10 +86,10 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
|
||||
thumbSizeMultiplier: 0.1,
|
||||
transformations: [new GrayscaleTransformation()],
|
||||
drawLifeCycle:this.createViewLifeCycle()
|
||||
drawLifeCycle: this.createViewLifeCycle()
|
||||
};
|
||||
}).margin({ left: 5 }).backgroundColor(Color.Blue)
|
||||
Button("网络webp")
|
||||
|
@ -94,10 +99,10 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
|
||||
placeholderSrc: $r('app.media.icon_loading'),
|
||||
errorholderSrc: $r('app.media.icon_failed'),
|
||||
|
||||
|
||||
thumbSizeMultiplier: 0.1,
|
||||
transformations: [new SketchFilterTransformation()],
|
||||
drawLifeCycle:this.createViewLifeCycle()
|
||||
drawLifeCycle: this.createViewLifeCycle()
|
||||
};
|
||||
}).margin({ left: 5 }).backgroundColor(Color.Blue)
|
||||
}.margin({ top: 15 })
|
||||
|
@ -119,42 +124,52 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
type: 'classic',
|
||||
name: 'ImageKnifeParseGIF'
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().setGifWorker(this.globalGifWorker)
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.setGifWorker(this.globalGifWorker)
|
||||
}
|
||||
aboutToDisappear(){
|
||||
if(this.globalGifWorker){
|
||||
|
||||
aboutToDisappear() {
|
||||
if (this.globalGifWorker) {
|
||||
this.globalGifWorker.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
drawMainAnimate(index, context, scaleType, imagePixelMap, widthPixel, heightPixel, compWidth, compHeight) {
|
||||
console.log('drawMainAnimate index = '+index)
|
||||
drawMainAnimate_index: number = 0;
|
||||
drawMainAnimate_context?: CanvasRenderingContext2D = undefined;
|
||||
drawMainAnimate_scaleType: ScaleType = ScaleType.FIT_CENTER;
|
||||
drawMainAnimate_imagePixelMap?: PixelMap = undefined;
|
||||
drawMainAnimate_widthPixel: number = 0;
|
||||
drawMainAnimate_heightPixel: number = 0;
|
||||
drawMainAnimate_compWidth: number = 0;
|
||||
drawMainAnimate_compHeight: number = 0;
|
||||
drawMainAnimate = () => {
|
||||
console.log('drawMainAnimate index = ' + this.drawMainAnimate_index)
|
||||
|
||||
let clipScale = (index / 30.0)
|
||||
context.save()
|
||||
context.beginPath();
|
||||
let clipScale = (this.drawMainAnimate_index / 30.0)
|
||||
this.drawMainAnimate_context?.save()
|
||||
this.drawMainAnimate_context?.beginPath();
|
||||
let path2d = new Path2D()
|
||||
let maxRadius = Math.sqrt(compWidth / 2 * compWidth / 2 + compHeight / 2 * compHeight / 2)
|
||||
path2d.arc(compWidth / 2, compHeight / 2, maxRadius * clipScale, 0, Math.PI * 2)
|
||||
context.clip(path2d)
|
||||
context.save()
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, imagePixelMap, px2vp(widthPixel), px2vp(heightPixel), compWidth, compHeight,0,0)
|
||||
context.restore();
|
||||
context.restore();
|
||||
if(index<30){
|
||||
index++
|
||||
let nextFunc = this.drawMainAnimate.bind(this,index, context, scaleType, imagePixelMap, widthPixel, heightPixel, compWidth, compHeight)
|
||||
// @ts-ignore
|
||||
this.mTimerId = setTimeout(nextFunc, 1000/30.0)
|
||||
}else{
|
||||
let maxRadius = Math.sqrt(this.drawMainAnimate_compWidth / 2 * this.drawMainAnimate_compWidth / 2 + this.drawMainAnimate_compHeight / 2 * this.drawMainAnimate_compHeight / 2)
|
||||
path2d.arc(this.drawMainAnimate_compWidth / 2, this.drawMainAnimate_compHeight / 2, maxRadius * clipScale, 0, Math.PI * 2)
|
||||
this.drawMainAnimate_context?.clip(path2d)
|
||||
this.drawMainAnimate_context?.save()
|
||||
ScaleTypeHelper.drawImageWithScaleType(this.drawMainAnimate_context!, this.drawMainAnimate_scaleType, this.drawMainAnimate_imagePixelMap, px2vp(this.drawMainAnimate_widthPixel), px2vp(this.drawMainAnimate_heightPixel), this.drawMainAnimate_compWidth, this.drawMainAnimate_compHeight, 0, 0)
|
||||
this.drawMainAnimate_context?.restore();
|
||||
this.drawMainAnimate_context?.restore();
|
||||
if (this.drawMainAnimate_index < 30) {
|
||||
this.drawMainAnimate_index++
|
||||
let nextFunc = this.drawMainAnimate
|
||||
|
||||
this.mTimerId = setTimeout(nextFunc, 1000 / 30.0)
|
||||
} else {
|
||||
// 不做处理
|
||||
}
|
||||
}
|
||||
private stopAnimate(){
|
||||
if(this.mTimerId > 0){
|
||||
|
||||
private stopAnimate() {
|
||||
if (this.mTimerId > 0) {
|
||||
clearTimeout(this.mTimerId)
|
||||
this.mTimerId = 0
|
||||
}else{
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -163,16 +178,16 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
let viewLifeCycle: IDrawLifeCycle = {
|
||||
// 展示占位图
|
||||
displayPlaceholder: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
this.stopAnimate()
|
||||
return false;
|
||||
},
|
||||
// 展示加载进度
|
||||
displayProgress: (context: CanvasRenderingContext2D, progress: number, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
this.stopAnimate()
|
||||
context.save();
|
||||
context.clearRect(0,0,compWidth,compHeight)
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
let pi = Math.PI * 2 / 100; //pi 讲圆的周长划分为100份
|
||||
let rate = progress - 25;
|
||||
let diameter = compWidth > compHeight ? compHeight : compWidth
|
||||
|
@ -213,7 +228,7 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
},
|
||||
// 展示缩略图
|
||||
displayThumbSizeMultiplier: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
this.stopAnimate()
|
||||
return false;
|
||||
},
|
||||
|
@ -222,14 +237,24 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
displayMainSource: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
this.stopAnimate()
|
||||
if (data.isPixelMap()) {
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
|
||||
data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => {
|
||||
let scaleType = (typeof imageKnifeOption.mainScaleType == 'number') ? imageKnifeOption.mainScaleType : ScaleType.FIT_CENTER
|
||||
console.log('imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height + 'scaleType=' + scaleType)
|
||||
|
||||
let func = this.drawMainAnimate.bind(this,0, context, scaleType, data.drawPixelMap.imagePixelMap, imageInfo.size.width, imageInfo.size.height, compWidth, compHeight)
|
||||
// @ts-ignore
|
||||
this.mTimerId = setTimeout(func, 1000/30.0)
|
||||
|
||||
this.drawMainAnimate_index = 0;
|
||||
this.drawMainAnimate_context = context;
|
||||
this.drawMainAnimate_scaleType = scaleType
|
||||
this.drawMainAnimate_imagePixelMap = data.drawPixelMap?.imagePixelMap
|
||||
this.drawMainAnimate_widthPixel = imageInfo.size.width
|
||||
this.drawMainAnimate_heightPixel = imageInfo.size.height
|
||||
this.drawMainAnimate_compWidth = compWidth
|
||||
this.drawMainAnimate_compHeight = compHeight
|
||||
|
||||
let func = this.drawMainAnimate
|
||||
|
||||
this.mTimerId = setTimeout(func, 1000 / 30.0)
|
||||
|
||||
console.log('TestImageKnifeOptionChangedPage4 drawMainSource end!')
|
||||
})
|
||||
|
@ -240,14 +265,14 @@ struct TestImageKnifeOptionChangedPage4 {
|
|||
|
||||
// 展示重试图层
|
||||
displayRetryholder: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
this.stopAnimate()
|
||||
return false;
|
||||
},
|
||||
|
||||
// 展示失败占位图
|
||||
displayErrorholder: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
this.stopAnimate()
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -25,12 +25,11 @@ import {
|
|||
ScaleType,
|
||||
ImageKnifeDrawFactory
|
||||
} from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker';
|
||||
@Entry
|
||||
@Component
|
||||
struct TestImageKnifeOptionChangedPage5 {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
|
@ -110,7 +109,7 @@ struct TestImageKnifeOptionChangedPage5 {
|
|||
}
|
||||
|
||||
private choiceViewLifeCycle(type:DrawType): IDrawLifeCycle {
|
||||
let viewLifeCycle = undefined;
|
||||
let viewLifeCycle:IDrawLifeCycle|undefined = undefined;
|
||||
switch(type){
|
||||
case DrawType.Oval:
|
||||
viewLifeCycle = ImageKnifeDrawFactory.createOvalLifeCycle(5,"#ff00ff")
|
||||
|
@ -123,7 +122,7 @@ struct TestImageKnifeOptionChangedPage5 {
|
|||
viewLifeCycle = {
|
||||
// 展示占位图
|
||||
displayPlaceholder: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
return false;
|
||||
},
|
||||
// 展示加载进度
|
||||
|
@ -132,20 +131,20 @@ struct TestImageKnifeOptionChangedPage5 {
|
|||
},
|
||||
// 展示缩略图
|
||||
displayThumbSizeMultiplier: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
// @ts-ignore
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
// 展示主图
|
||||
displayMainSource: (context: CanvasRenderingContext2D, data: ImageKnifeData, imageKnifeOption: ImageKnifeOption, compWidth: number, compHeight: number, setGifTimeId?: (timeId: number) => void) => {
|
||||
if (data.isPixelMap()) {
|
||||
// @ts-ignore
|
||||
data.drawPixelMap.imagePixelMap.getImageInfo().then((imageInfo) => {
|
||||
|
||||
data.drawPixelMap?.imagePixelMap?.getImageInfo().then((imageInfo) => {
|
||||
let scaleType = (typeof imageKnifeOption.mainScaleType == 'number') ? imageKnifeOption.mainScaleType : ScaleType.FIT_CENTER
|
||||
console.log('imageinfo width =' + imageInfo.size.width + ' height=' + imageInfo.size.height + 'scaleType=' + scaleType)
|
||||
context.save();
|
||||
context.clearRect(0, 0, compWidth, compHeight)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight,0,0)
|
||||
ScaleTypeHelper.drawImageWithScaleType(context, scaleType, data.drawPixelMap?.imagePixelMap, px2vp(imageInfo.size.width), px2vp(imageInfo.size.height), compWidth, compHeight,0,0)
|
||||
context.restore();
|
||||
console.log('TestImageKnifeOptionChangedPage4 drawMainSource end!')
|
||||
})
|
||||
|
|
|
@ -13,16 +13,17 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import {ImageKnifeComponent} from '@ohos/imageknife'
|
||||
import {ImageKnifeData} from '@ohos/imageknife'
|
||||
import {ImageKnifeOption} from '@ohos/imageknife'
|
||||
import {RequestOption} from '@ohos/imageknife'
|
||||
import {ImageKnifeGlobal } from '@ohos/imageknife'
|
||||
import ArkWorker from '@ohos.worker'
|
||||
import worker from '@ohos.worker'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct TestPreloadPage {
|
||||
private globalGifWorker:any = undefined
|
||||
private globalGifWorker?:worker.ThreadWorker = undefined
|
||||
@State imageKnifeOption1: ImageKnifeOption =
|
||||
{
|
||||
loadSrc: $r('app.media.jpgSample'),
|
||||
|
@ -83,15 +84,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.gifSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err) {
|
||||
console.log('预加载本地资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -117,15 +118,15 @@ struct TestPreloadPage {
|
|||
request.load($r('app.media.gifSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.dontAnimate()
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err ) {
|
||||
console.log('预加载本地资源gif静态 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源gif静态成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -152,15 +153,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -184,15 +185,15 @@ struct TestPreloadPage {
|
|||
request.load('https://gd-hbimg.huaban.com/e0a25a7cab0d7c2431978726971d61720732728a315ae-57EskW_fw658')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.dontAnimate()
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源gif静态 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif静态成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -223,15 +224,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.svgSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err ) {
|
||||
console.log('预加载本地资源svg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源svg成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -262,15 +263,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('http://124.222.187.78/download/test.svg')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err) {
|
||||
console.log('预加载网络资源gif 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源gif成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -303,15 +304,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.jpgSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源webp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -342,15 +343,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('https://hbimg.huabanimg.com/95a6d37a39aa0b70d48fa18dc7df8309e2e0e8e85571e-x4hhks_fw658/format/webp')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源webp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源webp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -381,15 +382,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.bmpSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -420,15 +421,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('https://img-blog.csdn.net/20140514114029140')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -459,15 +460,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.pngSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源png 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源png成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -498,15 +499,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('https://img-blog.csdnimg.cn/20191215043500229.png')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源bmp 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源bmp成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -537,15 +538,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load($r('app.media.jpgSample'))
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载本地资源jpg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载本地资源jpg成功! imageKnifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -576,15 +577,15 @@ struct TestPreloadPage {
|
|||
let request = new RequestOption();
|
||||
request.load('https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVggB')
|
||||
.setImageViewSize({ width: 300, height: 300 })
|
||||
.addListener((err, data) => {
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
if (err && err.length > 0) {
|
||||
console.log('预加载网络资源jpg 出现错误! err=' + err)
|
||||
} else {
|
||||
console.log('预加载网络资源jpg成功! imageknifedata=' + JSON.stringify(data))
|
||||
}
|
||||
return false;
|
||||
})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().preload(request);
|
||||
}})
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.preload(request);
|
||||
})
|
||||
.margin({ left: 15 })
|
||||
.backgroundColor(Color.Grey)
|
||||
|
@ -621,7 +622,7 @@ struct TestPreloadPage {
|
|||
name: 'ImageKnifeParseGIF'
|
||||
})
|
||||
// gif解析在子线程,请在页面构建后创建worker,注入imageknife
|
||||
ImageKnifeGlobal.getInstance().getImageKnife().setGifWorker(this.globalGifWorker)
|
||||
ImageKnifeGlobal.getInstance().getImageKnife()?.setGifWorker(this.globalGifWorker)
|
||||
}
|
||||
aboutToDisappear(){
|
||||
if(this.globalGifWorker){
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { ImageKnifeComponent } from '@ohos/imageknife/src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||
import { ImageKnifeOption } from '@ohos/imageknife/src/main/ets/components/imageknife/ImageKnifeOption'
|
||||
import { ImageKnifeComponent } from '@ohos/imageknife'
|
||||
import { ImageKnifeOption } from '@ohos/imageknife'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
|
|
|
@ -32,8 +32,8 @@ import { BlurTransformation } from '@ohos/imageknife'
|
|||
import { PixelationFilterTransformation } from '@ohos/imageknife'
|
||||
import { MaskTransformation } from '@ohos/imageknife'
|
||||
import { SwirlFilterTransformation } from '@ohos/imageknife'
|
||||
|
||||
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import {ImageKnifeData} from '@ohos/imageknife'
|
||||
/**
|
||||
* PixelMap transform 示例
|
||||
*/
|
||||
|
@ -45,28 +45,28 @@ let mUrl = $r('app.media.pngSample');
|
|||
@Component
|
||||
struct TransformPixelMapPage {
|
||||
@State url: string = "";
|
||||
@State mCropPixelMap: PixelMap = undefined;
|
||||
@State mRoundPixelMap: PixelMap = undefined;
|
||||
@State mCirclePixelMap: PixelMap = undefined;
|
||||
@State mCircleBorderPixelMap: PixelMap = undefined;
|
||||
@State mRotatePixelMap: PixelMap = undefined;
|
||||
@State mSquarePixelMap: PixelMap = undefined;
|
||||
@State mClipTopPixelMap: PixelMap = undefined;
|
||||
@State mClipCenterPixelMap: PixelMap = undefined;
|
||||
@State mClipBottomPixelMap: PixelMap = undefined;
|
||||
@State mGrayscalePixelMap: PixelMap = undefined;
|
||||
@State mBrightnessPixelMap: PixelMap = undefined;
|
||||
@State mContrastPixelMap: PixelMap = undefined;
|
||||
@State mInvertPixelMap: PixelMap = undefined;
|
||||
@State mSepiaPixelMap: PixelMap = undefined;
|
||||
@State mSketchPixelMap: PixelMap = undefined;
|
||||
@State mBlurPixelMap: PixelMap = undefined;
|
||||
@State mPixelPixelMap: PixelMap = undefined;
|
||||
@State mSwirlPixelMap: PixelMap = undefined;
|
||||
@State mMaskPixelMap: PixelMap = undefined;
|
||||
@State mKuwaharaPixelMap: PixelMap = undefined;
|
||||
@State mToonPixelMap: PixelMap = undefined;
|
||||
@State mVignettePixelMap: PixelMap = undefined;
|
||||
@State mCropPixelMap?: PixelMap = undefined;
|
||||
@State mRoundPixelMap?: PixelMap = undefined;
|
||||
@State mCirclePixelMap?: PixelMap = undefined;
|
||||
@State mCircleBorderPixelMap?: PixelMap = undefined;
|
||||
@State mRotatePixelMap?: PixelMap = undefined;
|
||||
@State mSquarePixelMap?: PixelMap = undefined;
|
||||
@State mClipTopPixelMap?: PixelMap = undefined;
|
||||
@State mClipCenterPixelMap?: PixelMap = undefined;
|
||||
@State mClipBottomPixelMap?: PixelMap = undefined;
|
||||
@State mGrayscalePixelMap?: PixelMap = undefined;
|
||||
@State mBrightnessPixelMap?: PixelMap = undefined;
|
||||
@State mContrastPixelMap?: PixelMap = undefined;
|
||||
@State mInvertPixelMap?: PixelMap = undefined;
|
||||
@State mSepiaPixelMap?: PixelMap = undefined;
|
||||
@State mSketchPixelMap?: PixelMap = undefined;
|
||||
@State mBlurPixelMap?: PixelMap = undefined;
|
||||
@State mPixelPixelMap?: PixelMap = undefined;
|
||||
@State mSwirlPixelMap?: PixelMap = undefined;
|
||||
@State mMaskPixelMap?: PixelMap = undefined;
|
||||
@State mKuwaharaPixelMap?: PixelMap = undefined;
|
||||
@State mToonPixelMap?: PixelMap = undefined;
|
||||
@State mVignettePixelMap?: PixelMap = undefined;
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
|
||||
|
@ -545,67 +545,49 @@ struct TransformPixelMapPage {
|
|||
* centerCrop
|
||||
*/
|
||||
centerCrop() {
|
||||
var imageKnifeOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.jpgSample'))
|
||||
// imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = undefined;
|
||||
result2 = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
}, 100)
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
this.mCropPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.centerCrop();
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* centerInside
|
||||
*/
|
||||
centerInside() {
|
||||
var imageKnifeOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load($r('app.media.Back'))
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = undefined;
|
||||
result2 = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
}, 100)
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
this.mCropPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.centerInside();
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* centerInside
|
||||
*/
|
||||
fitCenter() {
|
||||
var imageKnifeOption = new RequestOption()
|
||||
let imageKnifeOption = new RequestOption()
|
||||
imageKnifeOption.load($r('app.media.Back'))
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
this.mCropPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = undefined;
|
||||
result2 = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mCropPixelMap = result2;
|
||||
}, 100)
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
this.mCropPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.fitCenter();
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
/**
|
||||
* 圆角设置
|
||||
|
@ -613,18 +595,12 @@ struct TransformPixelMapPage {
|
|||
roundedCornersTransformation(top_left: number,
|
||||
bottom_left: number, top_right: number, bottom_right: number) {
|
||||
|
||||
var imageKnifeOption = new RequestOption();
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
this.mRoundPixelMap = result;
|
||||
setTimeout(() => {
|
||||
let result2 = undefined;
|
||||
result2 = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mRoundPixelMap = result2;
|
||||
}, 100)
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
this.mRoundPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(100), height: vp2px(100) })
|
||||
.skipMemoryCache(true)
|
||||
.roundedCorners({
|
||||
|
@ -633,7 +609,7 @@ struct TransformPixelMapPage {
|
|||
bottom_left: bottom_left,
|
||||
bottom_right: bottom_right
|
||||
})
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -642,16 +618,16 @@ struct TransformPixelMapPage {
|
|||
circleTransformation() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mCirclePixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mCirclePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.cropCircle()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -659,20 +635,20 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
circleBorderTransformation(border: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var circleTransformation = new CropCircleWithBorderTransformation(border,
|
||||
let circleTransformation = new CropCircleWithBorderTransformation(border,
|
||||
{ r_color: 255, g_color: 204, b_color: 204 });
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mCircleBorderPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mCircleBorderPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.cropCircleWithBorder(border,
|
||||
{ r_color: 255, g_color: 204, b_color: 204 })
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -680,18 +656,18 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
transformRotate(angled: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new RotateImageTransformation(angled);
|
||||
let transformation = new RotateImageTransformation(angled);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mRotatePixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mRotatePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.rotateImage(angled)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -699,18 +675,18 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
transformSquare() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new CropSquareTransformation();
|
||||
let transformation = new CropSquareTransformation();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mSquarePixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.cropSquare()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -718,26 +694,26 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
clipPixelMap(width: number, height: number, cropType: CropType) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new CropTransformation(width, height, cropType);
|
||||
let transformation = new CropTransformation(width, height, cropType);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
let result:PixelMap|undefined = undefined;
|
||||
if (cropType == CropType.TOP) {
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
result = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.mClipTopPixelMap = result;
|
||||
} else if (cropType == CropType.CENTER) {
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
result = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.mClipCenterPixelMap = result;
|
||||
} else if (cropType == CropType.BOTTOM) {
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
result = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
this.mClipBottomPixelMap = result;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: width, height: height })
|
||||
.skipMemoryCache(true)
|
||||
.crop(width, height, cropType)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -746,19 +722,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
grayscalePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new GrayscaleTransformation();
|
||||
let transformation = new GrayscaleTransformation();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mGrayscalePixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mGrayscalePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.grayscale()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -767,19 +743,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
brightnessPixelMap(brightness: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new BrightnessFilterTransformation(brightness);
|
||||
let transformation = new BrightnessFilterTransformation(brightness);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mBrightnessPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mBrightnessPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.brightnessFilter(brightness)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -788,19 +764,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
contrastPixelMap(contrast: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new ContrastFilterTransformation(contrast);
|
||||
let transformation = new ContrastFilterTransformation(contrast);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mContrastPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mContrastPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.contrastFilter(contrast)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -809,19 +785,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
invertPixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new InvertFilterTransformation();
|
||||
let transformation = new InvertFilterTransformation();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mInvertPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mInvertPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.invertFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -830,19 +806,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
sepiaPixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SepiaFilterTransformation();
|
||||
let transformation = new SepiaFilterTransformation();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mSepiaPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mSepiaPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.sepiaFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -851,19 +827,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
sketchPixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SketchFilterTransformation();
|
||||
let transformation = new SketchFilterTransformation();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mSketchPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mSketchPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.sketchFilter()
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -872,19 +848,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
blurHandlePixelMap(radius: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new BlurTransformation(radius);
|
||||
let transformation = new BlurTransformation(radius);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mBlurPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mBlurPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.blur(radius)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -892,19 +868,19 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
pixelHandlePixelMap(pixel: number) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new PixelationFilterTransformation(pixel);
|
||||
let transformation = new PixelationFilterTransformation(pixel);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mPixelPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mPixelPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.pixelationFilter(pixel)
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -913,20 +889,20 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
swirlHandlePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new SwirlFilterTransformation(80);
|
||||
let transformation = new SwirlFilterTransformation(80);
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mSwirlPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mSwirlPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.swirlFilter(80)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
/**
|
||||
|
@ -934,20 +910,20 @@ struct TransformPixelMapPage {
|
|||
*/
|
||||
maskHandlePixelMap(maskResource: Resource) {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
var transformation = new MaskTransformation(maskResource);
|
||||
let transformation = new MaskTransformation(maskResource);
|
||||
// imageKnifeOption.load($r('app.media.photo6'))
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mMaskPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mMaskPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.mask(maskResource)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -957,18 +933,18 @@ struct TransformPixelMapPage {
|
|||
kuwaharaHandlePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mKuwaharaPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mKuwaharaPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.kuwaharaFilter(20.0)
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -978,18 +954,18 @@ struct TransformPixelMapPage {
|
|||
toonHandlePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mToonPixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mToonPixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.toonFilter(0.2, 50.0);
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
|
||||
|
@ -999,20 +975,20 @@ struct TransformPixelMapPage {
|
|||
vignetteHandlePixelMap() {
|
||||
let imageKnifeOption = new RequestOption();
|
||||
imageKnifeOption.load(mUrl)
|
||||
.addListener((err, data) => {
|
||||
let result = undefined;
|
||||
result = data.drawPixelMap.imagePixelMap as PixelMap;
|
||||
this.mVignettePixelMap = result;
|
||||
.addListener({callback:(err:BusinessError|string, data:ImageKnifeData) => {
|
||||
|
||||
this.mVignettePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
|
||||
|
||||
return false;
|
||||
})
|
||||
}})
|
||||
.setImageViewSize({ width: vp2px(200), height: vp2px(200) })
|
||||
.skipMemoryCache(true)
|
||||
.enableGPU()
|
||||
.vignetteFilter([0.5, 0.5], [0.0, 0.0, 0.0], [0.3, 0.5])
|
||||
// .diskCacheStrategy(new NONE())
|
||||
ImageKnife.call(imageKnifeOption);
|
||||
ImageKnife?.call(imageKnifeOption);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var ImageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
|
||||
let ImageKnife = ImageKnifeGlobal.getInstance().getImageKnife();
|
|
@ -21,6 +21,7 @@
|
|||
export { FileUtils } from './src/main/ets/components/cache/FileUtils'
|
||||
export { Base64 } from './src/main/ets/components/cache/Base64'
|
||||
export { LruCache } from './src/main/ets/components/cache/LruCache'
|
||||
export { DiskStrategy } from './src/main/ets/components/cache/diskstrategy/DiskStrategy'
|
||||
export { ALL } from './src/main/ets/components/cache/diskstrategy/enum/ALL'
|
||||
export { AUTOMATIC } from './src/main/ets/components/cache/diskstrategy/enum/AUTOMATIC'
|
||||
export { DATA } from './src/main/ets/components/cache/diskstrategy/enum/DATA'
|
||||
|
@ -95,15 +96,16 @@ export { UPNG } from './src/main/ets/components/3rd_party/upng/UPNG'
|
|||
export { ImageKnife } from './src/main/ets/components/imageknife/ImageKnife'
|
||||
export { ImageKnifeGlobal } from './src/main/ets/components/imageknife/ImageKnifeGlobal'
|
||||
export {RequestOption,Size} from './src/main/ets/components/imageknife/RequestOption'
|
||||
export { ImageKnifeComponent } from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||
export { ImageKnifeComponent, ScaleType, ScaleTypeHelper } from './src/main/ets/components/imageknife/ImageKnifeComponent'
|
||||
export { ImageKnifeDrawFactory } from './src/main/ets/components/imageknife/ImageKnifeDrawFactory'
|
||||
export {ImageKnifeOption,CropCircleWithBorder,Crop,GifOptions,TransformOptions} from './src/main/ets/components/imageknife/ImageKnifeOption'
|
||||
export { ImageKnifeData } from './src/main/ets/components/imageknife/ImageKnifeData'
|
||||
export {IAllCacheInfoCallback} from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
||||
export {AllCacheInfo} from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
||||
export {IAllCacheInfoCallback,AllCacheInfo,ResourceCacheInfo,MemoryCacheInfo,DataCacheInfo} from './src/main/ets/components/imageknife/interface/IAllCacheInfoCallback'
|
||||
export {IParseImage} from './src/main/ets/components/imageknife/interface/IParseImage'
|
||||
export {IDataFetch} from './src/main/ets/components/imageknife/networkmanage/IDataFetch'
|
||||
export {ICache} from './src/main/ets/components/imageknife/requestmanage/ICache'
|
||||
export { FileTypeUtil } from './src/main/ets/components/imageknife/utils/FileTypeUtil'
|
||||
export { ParseImageUtil } from './src/main/ets/components/imageknife/utils/ParseImageUtil'
|
||||
|
||||
/**
|
||||
* svg parse
|
||||
|
|
Loading…
Reference in New Issue