diff --git a/entry/src/main/ets/pages/cropImagePage2.ets b/entry/src/main/ets/pages/cropImagePage2.ets index c65273b..8bc2893 100644 --- a/entry/src/main/ets/pages/cropImagePage2.ets +++ b/entry/src/main/ets/pages/cropImagePage2.ets @@ -17,17 +17,18 @@ 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 { CropCallback } from '@ohos/imageknife' import { FileUtils } from '@ohos/imageknife' import { ImageKnifeGlobal } from '@ohos/imageknife' - +import { BusinessError } from '@ohos.base' @Entry @Component export struct CropImagePage2 { - @State options1: PixelMapCrop.Options = new PixelMapCrop.Options(); + @State options1: Options = new Options(); @State cropTap: boolean = false; @State width1: number = 0; @@ -46,10 +47,10 @@ export struct CropImagePage2 { .getMediaContent($r('app.media.bmpSample').id) .then(data => { let arrayBuffer = FileUtils.getInstance().uint8ArrayToBuffer(data); - let optionx = new PixelMapCrop.Options(); + let optionx = new Options(); optionx.setWidth(800) .setHeight(800) - .setCropFunction((err, pixelmap, sx, sy) => { + .setCropFunction((err:BusinessError, pixelmap:PixelMap, sx:number, sy:number) => { console.log('PMC setCropFunction callback') if (err) { console.error('PMC crop err =' + err) diff --git a/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets b/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets index b629382..ca6c4c4 100644 --- a/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets +++ b/imageknife/src/main/ets/components/imageknife/crop/PixelMapCrop.ets @@ -802,7 +802,7 @@ export class Options { pixelScale: number = 1; // 用户裁剪后的回调 - cropFunction: (error:BusinessError, pixelmap:PixelMap, sx:number, sy:number) => void = (error:BusinessError, pixelmap:PixelMap, sx:number, sy:number)=>{}; + cropFunction: (error:BusinessError|string, pixelmap:PixelMap, sx:number, sy:number) => void = (error:BusinessError, pixelmap:PixelMap, sx:number, sy:number)=>{}; // 本地裁剪框 回调 cropAction: (topLeftPoint:number[], bottomRightPoint:number[], scaleInside:number) =>void = (topLeftPoint:number[], bottomRightPoint:number[], scaleInside:number)=>{}; diff --git a/imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ets b/imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ts similarity index 93% rename from imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ets rename to imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ts index 54d0bbd..3d3b297 100644 --- a/imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ets +++ b/imageknife/src/main/ets/components/imageknife/pngj/PngCallback.ts @@ -14,5 +14,5 @@ */ export interface PngCallback{ - (sender:R, receover:T) + pngCallback: (sender:R, receover:T)=>void } \ No newline at end of file diff --git a/imageknife/src/main/ets/components/imageknife/pngj/PngReader.ets b/imageknife/src/main/ets/components/imageknife/pngj/PngReader.ets index 26c2934..45592fd 100644 --- a/imageknife/src/main/ets/components/imageknife/pngj/PngReader.ets +++ b/imageknife/src/main/ets/components/imageknife/pngj/PngReader.ets @@ -12,16 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {Closeable} from "/imageknife/pngj/io/Closeable" -import {ImageInfo} from "/imageknife/pngj/entry/ImageInfo" +import {Closeable} from "./io/Closeable" +import {ImageInfo} from "./entry/ImageInfo" export class PngReader implements Closeable { private static LOG_TAG: string= "PngReader"; private static MAX_TOTAL_BYTES_READ_DEFAULT: number= 901001001; private static MAX_BYTES_METADATA_DEFAULT: number= 5024024; private static MAX_CHUNK_SIZE_SKIP: number= 2024024; - public imgInfo: ImageInfo; - public interlaced: boolean; + public imgInfo: ImageInfo = new ImageInfo(0,0,0,false,false,false); + public interlaced: boolean = false; constructor(shouldCloseStream: boolean) { diff --git a/imageknife/src/main/ets/components/imageknife/pngj/Pngj.ets b/imageknife/src/main/ets/components/imageknife/pngj/Pngj.ts similarity index 85% rename from imageknife/src/main/ets/components/imageknife/pngj/Pngj.ets rename to imageknife/src/main/ets/components/imageknife/pngj/Pngj.ts index 16f03c6..fb94dfe 100644 --- a/imageknife/src/main/ets/components/imageknife/pngj/Pngj.ets +++ b/imageknife/src/main/ets/components/imageknife/pngj/Pngj.ts @@ -13,20 +13,20 @@ * limitations under the License. */ import {UPNG} from '../../3rd_party/upng/UPNG'; -import {PngCallback} from '../pngj/PngCallback'; +import {PngCallback} from './PngCallback'; import image from '@ohos.multimedia.image'; import resourceManager from '@ohos.resourceManager'; import ArkWorker from '@ohos.worker' - +import { BusinessError } from '@ohos.base' export class Pngj { - readPngImageInfo(arraybuffer: ArrayBuffer, callback:PngCallback) { - let imageSource = image.createImageSource(arraybuffer as any); + readPngImageInfo(arraybuffer: ArrayBuffer, callback:PngCallback) { + let imageSource:image.ImageSource = image.createImageSource(arraybuffer); if (imageSource != undefined){ - imageSource.getImageInfo((err, value) => { + imageSource.getImageInfo((err:BusinessError, value:image.ImageInfo) => { if (err) { return; } - callback(arraybuffer, value); + callback.pngCallback(arraybuffer, value); }); } @@ -47,19 +47,19 @@ export class Pngj { */ readPngImage(pngBuffer: ArrayBuffer, callback:PngCallback) { var png = UPNG.decode(pngBuffer); - callback(pngBuffer, png) + callback.pngCallback(pngBuffer, png) } writePngWithString(addInfo:string, pngBuffer: ArrayBuffer,callback:PngCallback) { var pngDecode = UPNG.decode(pngBuffer); var newPng = UPNG.encodeWithString(addInfo, UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0) - callback(pngBuffer, newPng); + callback.pngCallback(pngBuffer, newPng); } writePng(pngBuffer: ArrayBuffer,callback:PngCallback) { var pngDecode = UPNG.decode(pngBuffer); var newPng = UPNG.encode(UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0) - callback(pngBuffer, newPng); + callback.pngCallback(pngBuffer, newPng); } readPngImageAsync(worker: any, pngBuffer: ArrayBuffer, callback: PngCallback) { @@ -79,7 +79,7 @@ export class Pngj { var data = e.data; switch (data.type) { case 'readPngImageAsync': - callback(data.receiver, data.data) + callback.pngCallback(data.receiver, data.data) break; default: break @@ -107,7 +107,7 @@ export class Pngj { var data = e.data; switch (data.type) { case 'writePngWithStringAsync': - callback(data.receiver, data.data) + callback.pngCallback(data.receiver, data.data) break; default: break @@ -137,7 +137,7 @@ export class Pngj { var data = e.data; switch (data.type) { case 'writePngAsync': - callback(data.receiver, data.data) + callback.pngCallback(data.receiver, data.data) break; default: break diff --git a/imageknife/src/main/ets/components/imageknife/pngj/entry/ImageInfo.ets b/imageknife/src/main/ets/components/imageknife/pngj/entry/ImageInfo.ets index 9de32ec..a6bf73b 100644 --- a/imageknife/src/main/ets/components/imageknife/pngj/entry/ImageInfo.ets +++ b/imageknife/src/main/ets/components/imageknife/pngj/entry/ImageInfo.ets @@ -162,7 +162,7 @@ export class ImageInfo { return true; if (obj == null) return false; - var other = obj; + let other = obj; if (this.alpha != other.alpha) return false; if (this.bitDepth != other.bitDepth)