Merge branch 'master' of https://gitee.com/tianshuangming/ImageKnife
# Conflicts: # library/src/main/ets/components/imageknife/Downsampling/BaseDownsampling.ets # library/src/main/ets/components/imageknife/Downsampling/DownsampleStartegy.ets # library/src/main/ets/components/imageknife/Downsampling/Downsampler.ets # library/src/main/ets/components/imageknife/utils/ParseImageUtil.ets
This commit is contained in:
commit
bc3c1852f6
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"hvigorVersion": "3.0.9",
|
||||
"hvigorVersion": "4.1.2",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "3.0.9"
|
||||
"@ohos/hvigor-ohos-plugin": "4.1.2"
|
||||
}
|
||||
}
|
|
@ -1,2 +1,6 @@
|
|||
/*
|
||||
* asdfasdfasdfasdfasdf*/
|
||||
export interface BaseDownsampling{
|
||||
getScaleFactor(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):number
|
||||
|
||||
|
||||
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):number
|
||||
}
|
|
@ -1,2 +1,79 @@
|
|||
/*
|
||||
* dsasdafasdfasdf*/
|
||||
import { BaseDownsampling } from './BaseDownsampling'
|
||||
|
||||
|
||||
export class CenterInside{
|
||||
getScaleFactor(sourceWidth:number, sourceHeight:number,requestWidth:number, requestHeight:number):number {
|
||||
|
||||
return Math.min(1,FitCenter.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight))
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth:number, sourceHeight:number, requestWidth:number, requestHeight:number):SampleSizeRounding {
|
||||
return this.getScaleFactor(sourceWidth, sourceHeight, requestWidth, requestHeight)==1
|
||||
?SampleSizeRounding.QUALITY
|
||||
:FitCenter.getSampleSizeRounding(sourceWidth, sourceHeight, requestWidth, requestHeight)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/*不进行下采样*/
|
||||
export class DownsampleNone implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return 1
|
||||
}
|
||||
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
}
|
||||
|
||||
}
|
||||
/* 下采样使得图像的组大尺寸在给定的尺寸的1/2之间*/
|
||||
export class AtMost implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth:number,requestHeight: number): number {
|
||||
let maxIntegerFactor=Math.ceil(Math.max(sourceHeight/requestHeight,sourceWidth/requestWidth));
|
||||
let lesserOrEqualSampleSize = Math.max(1,highestOneBit(maxIntegerFactor))
|
||||
let greaterOrEqualSampleSize = lesserOrEqualSampleSize<<(lesserOrEqualSampleSize<maxIntegerFactor?1:0)
|
||||
return 1/greaterOrEqualSampleSize
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.MEMORY
|
||||
}
|
||||
}
|
||||
export class Atleast implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let minIntegerFactor=Math.floor(Math.min(sourceHeight/requestHeight,sourceWidth/requestWidth))
|
||||
|
||||
return minIntegerFactor==0?1:1/highestOneBit(minIntegerFactor)
|
||||
}
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
}
|
||||
}
|
||||
export class CenterOutside implements BaseDownsampling{
|
||||
getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let widthPercentage =requestWidth/sourceWidth
|
||||
let heightPercentage =requestHeight/sourceHeight
|
||||
return Math.max(widthPercentage,heightPercentage)
|
||||
}
|
||||
|
||||
getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.QUALITY
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export class FitCenter{
|
||||
public static getScaleFactor(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
let widthPercentage =requestWidth/sourceWidth
|
||||
let heightPercentage =requestHeight/sourceHeight
|
||||
return Math.min(widthPercentage,heightPercentage)
|
||||
}
|
||||
public static getSampleSizeRounding(sourceWidth: number, sourceHeight: number, requestWidth: number, requestHeight: number): number {
|
||||
return SampleSizeRounding.MEMORY
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export enum SampleSizeRounding{
|
||||
MEMORY,
|
||||
QUALITY
|
||||
}
|
|
@ -1,2 +1,140 @@
|
|||
/*
|
||||
* asdfasdfasdfasdfasdf*/
|
||||
* asdfasdfasdfasdfasdf*/
|
||||
import { CenterOutside, FitCenter, SampleSizeRounding } from './Downsamplestrategy';
|
||||
import { FileTypeUtil } from '../../utits/Fitetypeutit';
|
||||
import { RequestOption } from '../../Requestoption';
|
||||
let TAG = 'downsampling'
|
||||
export class Downsampler {
|
||||
calculateScaling(
|
||||
imageType: ArrayBuffer,
|
||||
sourceHeight:number,
|
||||
sourceWidth:number,
|
||||
request?: RequestOption
|
||||
):ESObject {
|
||||
const fileType: string | null = new FileTypeUtil().getFileType(imageType)
|
||||
let powerOfTwoWidth: number | null = null;
|
||||
let powerOfTwoHeight: number | null = null;
|
||||
let targetWidth: number = 0
|
||||
let targetHeight: number = 0
|
||||
if (request?.size.width && !request?.size.height) {
|
||||
targetWidth = this.round((request?.size.height) * sourceWidth / sourceHeight)
|
||||
} else if (request?.size.height && !request?.size.width) {
|
||||
targetHeight = this.round((request?.size.width) * sourceHeight / sourceWidth)
|
||||
} else if (request?.size.height && request?.size.width) {
|
||||
targetHeight = request.size.height;
|
||||
targetWidth = request?.size.width;
|
||||
} else {
|
||||
console.log('宽高都不存在')
|
||||
}
|
||||
if (sourceWidth <= 0 || sourceleight <= 0) return;
|
||||
let orientedSourceWidth = sourceWidth;
|
||||
let orientedSourceHeight = sourceHeight;
|
||||
if (this.isRotationRequired(90)) {
|
||||
orientedSourceWidth = sourceHeight;
|
||||
orientedSourceHeight = sourceWidth;
|
||||
}
|
||||
/*安卓的模式*/
|
||||
let exactScaleFactor: number = FitCenter.getScaleFactor(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||
if (exactScaleFactor <= 0) {
|
||||
throw new Error("Cannot round with exactScaleFactor");
|
||||
}
|
||||
console.log('exactScaleFactor', exactScaleFactor)
|
||||
/*安卓的模式*/
|
||||
let rounding: SampleSizeRounding = CenterOutside.getSampleSizeRounding(orientedSourceWidth, orientedSourceHeight, targetWidth, targetHeight)
|
||||
if (rounding == null) {
|
||||
throw new Error("Cannot round with null rounding");
|
||||
}
|
||||
let outWidth: number = this.round(exactScaleFactor * orientedSourceWidth);
|
||||
let outHeight: number = this.round(exactScaleFactor * orientedSourceHeight);
|
||||
let widthScaleFactor = Math.floor(orientedSourceWidth / outWidth);
|
||||
let heightScaleFactor = Math.floor(orientedSourceHeight / outHeight);
|
||||
let scaleFactor = rounding == SampleSizeRounding.MEMORY ? Math.max(widthScaleFactor, heightScaleFactor) : Math.min(widthScaleFactor, heightScaleFactor)
|
||||
let powerOfTwoSampleSize: number;
|
||||
powerOfTwoSampleSize = Math.max(1, this.highestOneBit(scaleFactor));
|
||||
if (fileType == "JPEG") {
|
||||
let nativeScaling = Hath.min(powerOfTwoSampleSize, 8);
|
||||
powerOfTwoWidth = Math.ceil(orientedSourceWidth / nativeScaling);
|
||||
powerOfTwoHeight = Math.ceil(orientedSourceHeight / nativeScaling);
|
||||
let secondaryScaling = Math.floor(powerOfTwoSampleSize / 8);
|
||||
if (secondaryScaling > 0) {
|
||||
powerOfTwoWidth = powerOfTwoWidth / secondaryScaling;
|
||||
powerOfTwoHeight = powerOfTwoHeight / secondaryScaling;
|
||||
}
|
||||
} else if (fileType == "PNG") {
|
||||
powerOfTwoWidth = Math.floor(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
PowerOfTwoHeight = Math.floor(orientedSourceHeight / powerOfTwoSamplesize);
|
||||
console.log('执行了没', powerOfTwoHeight, powerOfTwoWidth)
|
||||
} else if (fileType == "WEBP") {
|
||||
powerOfTwoWidth = Math.round(orientedSourceWidth / powerOfTwoSampleSize);
|
||||
poWerOfTwoHeight = Math.round(orientedSourceHeight / powerOfTwoSampleSize);
|
||||
} else if (
|
||||
orientedSourceWidth % powerOfTwoSampleSize != 0 || orientedSourceHeight % powerOfTwoSampleSize != 0) {
|
||||
|
||||
|
||||
// let dimensions; number[] = this.getDimensions(imageReader, options, decodeCallbacks,bitmapPool);
|
||||
// powerOfTwoWidth = dimensions[0];
|
||||
// powerofTwoHeight = dimensions[1];
|
||||
} else {
|
||||
powerOfTwoWidth = orientedSourceWidth / powerOfTwoSampleSize;
|
||||
powerOfTwoHeight = orientedSourceHeight / powerOfTwoSampleSize;
|
||||
}
|
||||
// Let adjustedScaleFactor = downsampleStrategy.getScaleFactor(powerOfTwoWidth, powerOfTwoHeight, targetWidth, targetHeight);
|
||||
// Density scaling is only supported if inBitmap is null prior to KitKat. Avoid setting
|
||||
// densities here so we calculate the final Bitmap size correctly.
|
||||
// if (Build.VERSION,SDK_INT >=Build.VERSION_CODES.KITKAT) {
|
||||
// options.inTargetDensity = this.adjustTargetDensityForError(adjustedScaleFactor);
|
||||
// options,inDensity = this.getDensityMultiplier(adjustedScaleFactor);
|
||||
//}
|
||||
// if (this.isScaling(options)){
|
||||
// options.inScaled = true;
|
||||
// }else {
|
||||
// options.inDensity = options.inTargetDensity =0;
|
||||
// }
|
||||
//}
|
||||
let a: ESObject = { "targetWidth": power0fTwoWidth, "targetHeight": powerOfTuoHeight }
|
||||
return a
|
||||
}
|
||||
//decodeStream(imageReader:ImageReader, options: ESObject, callbacks: DecodeCallbacks, bitmapPool: ESObject) {
|
||||
//if (!options.inJustDecodeBounds){
|
||||
// callbacks.onObtainBounds();
|
||||
// imageReader.stopGrowingBuffers();
|
||||
// }
|
||||
// }
|
||||
// getDimensions(imageReader: ImageReader, options: ESObject, decodeCallbacks: DecodeCallbacks, bitmapPool: ESObject):number[] {
|
||||
// options.inJustDecodeBounds = true;
|
||||
// this.decodeStream(imageReader, options, decodeCallbacks, bitmapPool);
|
||||
// options.inJustDecodeBounds =false;
|
||||
// return new Array(options.outWidth, options,outHeight);
|
||||
//
|
||||
// }
|
||||
|
||||
highest0neBit(i: number): number{
|
||||
i |= (i >> 1);
|
||||
i |= (i >> 2);
|
||||
i |= (i >> 4);
|
||||
i |= (i >> 8);
|
||||
i |= (i >> 16);
|
||||
return i - (i >>> 1);
|
||||
}
|
||||
round(value: number): number {
|
||||
return Math.floor(value +0.5);
|
||||
}
|
||||
isRotationRequired(degreesToRotate: number): boolean {
|
||||
return degreesToRotate == 90 || degreesToRotate == 270;
|
||||
}
|
||||
// isScaling(options: ESObject): boolean {
|
||||
// return options.inTargetDensity >0
|
||||
// && options.inDensity>0
|
||||
// && options.inTargetDensity != options.inDensity;
|
||||
//}
|
||||
getDensityMultiplier(adjustedScaleFactor: number):number{
|
||||
return Math.round(Number.MAX_VALUE * (adjustedScaleFactor <= 1 ? adjustedScaleFactor : 1 / adjustedScaleFactor));
|
||||
}
|
||||
adjustTargetDensityForError(adjustedScaleFactor:number):number{
|
||||
let densityMultiplier = this.getDensityMultiplier(adjustedScaleFactor);
|
||||
let targetDensity = this.round(densityMultiplier * adjustedScaleFactor);
|
||||
let scaleFactorWithError = targetDensity / densityMultiplier;
|
||||
let difference = adjustedScaleFactor / scaleFactorWithError;
|
||||
return this.round(difference * targetDensity);
|
||||
}
|
||||
}
|
|
@ -242,6 +242,9 @@ export struct ImageKnifeComponent {
|
|||
if (this.imageKnifeOption.signature) {
|
||||
request.signature = this.imageKnifeOption.signature;
|
||||
}
|
||||
if(this.imageKnifeOption.downsampling){
|
||||
request.downsampleStrategy(this.imageKnifeOption.downsampling)
|
||||
}
|
||||
}
|
||||
|
||||
configDisplay(request: RequestOption) {
|
||||
|
|
|
@ -60,6 +60,7 @@ import { SparkMD5 } from '../3rd_party/sparkmd5/spark-md5'
|
|||
import { FileUtils } from '../cache/FileUtils'
|
||||
import util from '@ohos.util'
|
||||
import { DataFetchResult } from './networkmanage/DataFetchResult'
|
||||
import { BaseDownsampling } from './Downsampling/BaseDownsampling'
|
||||
|
||||
export interface Size {
|
||||
width: number,
|
||||
|
@ -106,6 +107,8 @@ export class RequestOption {
|
|||
uuid: string = '' // 唯一标识
|
||||
loadSrc: string | PixelMap | Resource = '';
|
||||
strategy: DiskStrategy = new AUTOMATIC();
|
||||
//下采样相关
|
||||
downsampType: BaseDownsampling = new BaseDownsamplings()
|
||||
dontAnimateFlag = false;
|
||||
placeholderSrc: string | PixelMap | Resource | undefined = undefined;
|
||||
placeholderFunc: AsyncSuccess<ImageKnifeData> | undefined = undefined;
|
||||
|
@ -502,6 +505,10 @@ export class RequestOption {
|
|||
this.gpuEnabled = true;
|
||||
return this;
|
||||
}
|
||||
downsampleStrategy(downsampType: ESObject){
|
||||
this.downsampType = downsampType
|
||||
return this;
|
||||
}
|
||||
|
||||
// 占位图解析成功
|
||||
placeholderOnComplete = (imageKnifeData:ImageKnifeData) => {
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { RequestOption } from '../RequestOption';
|
||||
|
||||
export interface IParseImage<T> {
|
||||
parseImage:(imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||
parseImage:(imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void,request?:RequestOption)=>void;
|
||||
parseImageThumbnail:(scale:number, imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>,
|
||||
onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||
}
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {UPNG} from '../../3rd_party/upng/UPNG';
|
||||
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<ArrayBuffer, image.ImageInfo>) {
|
||||
let imageSource:image.ImageSource = image.createImageSource(arraybuffer);
|
||||
if (imageSource != undefined){
|
||||
imageSource.getImageInfo((err:BusinessError, value:image.ImageInfo) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
callback.pngCallback(arraybuffer, value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
readPngImage(pngBuffer: ArrayBuffer, callback:PngCallback<ArrayBuffer, any>) {
|
||||
var png = UPNG.decode(pngBuffer);
|
||||
callback.pngCallback(pngBuffer, png)
|
||||
}
|
||||
|
||||
writePngWithString(addInfo:string, pngBuffer: ArrayBuffer,callback:PngCallback<ArrayBuffer, any>) {
|
||||
var pngDecode = UPNG.decode(pngBuffer);
|
||||
var newPng = UPNG.encodeWithString(addInfo, UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0)
|
||||
callback.pngCallback(pngBuffer, newPng);
|
||||
}
|
||||
|
||||
writePng(pngBuffer: ArrayBuffer,callback:PngCallback<ArrayBuffer, any>) {
|
||||
var pngDecode = UPNG.decode(pngBuffer);
|
||||
var newPng = UPNG.encode(UPNG.toRGBA8(pngDecode), pngDecode.width, pngDecode.height, 0)
|
||||
callback.pngCallback(pngBuffer, newPng);
|
||||
}
|
||||
|
||||
readPngImageAsync(type: any, pngBuffer: ArrayBuffer, callback: PngCallback<ArrayBuffer, any>) {
|
||||
// worker.onerror = function (data) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// worker.onmessageerror = function (e) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// worker.onexit = function () {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// worker.onmessage = function(e) {
|
||||
// var data = e.data;
|
||||
// switch (data.type) {
|
||||
// case 'readPngImageAsync':
|
||||
// callback.pngCallback(data.receiver, data.data)
|
||||
// break;
|
||||
// default:
|
||||
// break
|
||||
// }
|
||||
// worker.terminate();
|
||||
// }
|
||||
// var obj = { type: 'readPngImageAsync', data: pngBuffer }
|
||||
// worker.postMessage(obj, [pngBuffer])
|
||||
let task = new taskpool.Task(taskParseImage,type, arrayBuffer, callback)
|
||||
// task.setTransferList([])
|
||||
taskpool.execute(task).then((pixelmap: Object) => {
|
||||
LogUtil.log('ceshi321 : Succeeded in creating pixelmap Ui .' + (pixelmap as image.PixelMap).getPixelBytesNumber())
|
||||
onCompleteFunction(pixelmap as image.PixelMap);
|
||||
}).catch((err: string) => {
|
||||
LogUtil.log("ceshi321 : test occur error: " + err)
|
||||
onErrorFunction(err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
// taskPoolExecutePixelMap(arrayBuffer: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void) {
|
||||
// let task = new taskpool.Task(taskParseImage, arrayBuffer, scale)
|
||||
// task.setTransferList([])
|
||||
// taskpool.execute(task).then((pixelmap: Object) => {
|
||||
//
|
||||
// }).catch((err: string) => {
|
||||
// LogUtil.log("ceshi321 : " + err)
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
writePngWithStringAsync(worker: any, addInfo: string, pngBuffer: ArrayBuffer, callback: PngCallback<ArrayBuffer, any>) {
|
||||
worker.onerror = function (data) {
|
||||
|
||||
}
|
||||
|
||||
worker.onmessageerror = function (e) {
|
||||
|
||||
}
|
||||
|
||||
worker.onexit = function () {
|
||||
|
||||
}
|
||||
|
||||
worker.onmessage = function(e) {
|
||||
var data = e.data;
|
||||
switch (data.type) {
|
||||
case 'writePngWithStringAsync':
|
||||
callback.pngCallback(data.receiver, data.data)
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
worker.terminate();
|
||||
}
|
||||
|
||||
var obj = { type: 'writePngWithStringAsync', data:pngBuffer, info: addInfo}
|
||||
worker.postMessage(obj, [pngBuffer])
|
||||
|
||||
}
|
||||
|
||||
writePngAsync(worker: any, pngBuffer: ArrayBuffer, callback: PngCallback<ArrayBuffer, any>) {
|
||||
worker.onerror = function (data) {
|
||||
|
||||
}
|
||||
|
||||
worker.onmessageerror = function (e) {
|
||||
|
||||
}
|
||||
|
||||
worker.onexit = function () {
|
||||
|
||||
}
|
||||
|
||||
worker.onmessage = function(e) {
|
||||
var data = e.data;
|
||||
switch (data.type) {
|
||||
case 'writePngAsync':
|
||||
callback.pngCallback(data.receiver, data.data)
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
worker.terminate();
|
||||
}
|
||||
|
||||
var obj = { type: 'writePngAsync', data:pngBuffer}
|
||||
worker.postMessage(obj, [pngBuffer])
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@Concurrent
|
||||
async function taskParseImage(type, arrayBuffer, callback): Promise<PixelMap> {
|
||||
|
||||
switch (type.type) {
|
||||
case 'readPngImageAsync':
|
||||
callback(data.receiver, data.data)
|
||||
break;
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
let obj = { type: 'readPngImageAsync', data: arrayBuffer }
|
||||
|
||||
return (obj,[arrayBuffer])
|
||||
}
|
||||
|
||||
// function taskPoolExecutePixelMap(arrayBuffer: ArrayBuffer, scale: number, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void) {
|
||||
// LogUtil.log("ceshi321 : arrayBuffer长度" + arrayBuffer.byteLength)
|
||||
// let task = new taskpool.Task(taskParseImage, arrayBuffer, scale)
|
||||
// task.setTransferList([])
|
||||
// taskpool.execute(task).then((pixelmap: Object) => {
|
||||
// LogUtil.log('ceshi321 : Succeeded in creating pixelmap Ui .' + (pixelmap as image.PixelMap).getPixelBytesNumber())
|
||||
// onCompleteFunction(pixelmap as image.PixelMap);
|
||||
// }).catch((err: string) => {
|
||||
// LogUtil.log("ceshi321 : test occur error: " + err)
|
||||
// onErrorFunction(err);
|
||||
// });
|
||||
// }
|
|
@ -16,22 +16,14 @@
|
|||
import { IParseImage } from '../interface/IParseImage'
|
||||
import image from '@ohos.multimedia.image';
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import taskpool from '@ohos.taskpool';
|
||||
import { LogUtil } from './LogUtil';
|
||||
import { RequestOption } from '../RequestOption';
|
||||
|
||||
export class ParseImageUtil implements IParseImage<PixelMap> {
|
||||
parseImage(
|
||||
imageinfo: ArrayBuffer,
|
||||
|
||||
onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>,
|
||||
|
||||
onErrorFunction: (reason?: BusinessError | string) => void,
|
||||
request?: RequestOption
|
||||
) {
|
||||
this.parseImageThumbnail(1, imageinfo, onCompleteFunction, onErrorFunction)
|
||||
parseImage(imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void,request?:RequestOption) {
|
||||
this.parseImageThumbnail(1, imageinfo, onCompleteFunction, onErrorFunction,request)
|
||||
}
|
||||
|
||||
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void) {
|
||||
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction: (value: PixelMap) => void | PromiseLike<PixelMap>, onErrorFunction: (reason?: BusinessError | string) => void,request?:RequestOption) {
|
||||
|
||||
let imageSource: image.ImageSource = image.createImageSource(imageinfo); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
||||
imageSource.getImageInfo().then((value) => {
|
||||
|
@ -45,6 +37,15 @@ export class ParseImageUtil implements IParseImage<PixelMap> {
|
|||
editable: true,
|
||||
desiredSize: defaultSize
|
||||
};
|
||||
const b = new Downsamper(imageinfo, hValue, wValue, requ,request)
|
||||
let options: image.DecodingOptions = {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
height: b.targetHeight,
|
||||
width: b.targetWidth
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
|
||||
onCompleteFunction(pixelMap);
|
||||
|
|
Loading…
Reference in New Issue