forked from floraachy/ImageKnife
1.ArkTs整改8 整改imageknife->holder/interface/部分utils
Signed-off-by: zhoulisheng1 <zhoulisheng1@huawei.com>
This commit is contained in:
parent
50116741ea
commit
af84eb8ab4
|
@ -370,7 +370,7 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 占位图解析成功
|
// 占位图解析成功
|
||||||
placeholderOnComplete(imageKnifeData: ImageKnifeData) {
|
placeholderOnComplete = (imageKnifeData: ImageKnifeData)=> {
|
||||||
LogUtil.log("placeholderOnComplete has called!");
|
LogUtil.log("placeholderOnComplete has called!");
|
||||||
LogUtil.log("Main Image is Ready:" + this.loadMainReady);
|
LogUtil.log("Main Image is Ready:" + this.loadMainReady);
|
||||||
if (!this.loadMainReady && !(this.loadErrorReady || this.loadRetryReady) && !this.loadThumbnailReady) {
|
if (!this.loadMainReady && !(this.loadErrorReady || this.loadRetryReady) && !this.loadThumbnailReady) {
|
||||||
|
@ -380,7 +380,7 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 占位图解析失败
|
// 占位图解析失败
|
||||||
placeholderOnError(error) {
|
placeholderOnError = (error)=>{
|
||||||
LogUtil.log("占位图解析失败 error =" + error)
|
LogUtil.log("占位图解析失败 error =" + error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载失败 占位图解析成功
|
// 加载失败 占位图解析成功
|
||||||
errorholderOnComplete(imageKnifeData: ImageKnifeData) {
|
errorholderOnComplete = (imageKnifeData: ImageKnifeData)=> {
|
||||||
// 如果有错误占位图 先解析并保存在RequestOption中 等到加载失败时候进行调用
|
// 如果有错误占位图 先解析并保存在RequestOption中 等到加载失败时候进行调用
|
||||||
this.errorholderData = imageKnifeData;
|
this.errorholderData = imageKnifeData;
|
||||||
if (this.loadErrorReady) {
|
if (this.loadErrorReady) {
|
||||||
|
@ -408,18 +408,18 @@ export class RequestOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
//加载失败 占位图解析失败
|
//加载失败 占位图解析失败
|
||||||
errorholderOnError(error) {
|
errorholderOnError = (error)=> {
|
||||||
LogUtil.log("失败占位图解析失败 error =" + error)
|
LogUtil.log("失败占位图解析失败 error =" + error)
|
||||||
}
|
}
|
||||||
|
|
||||||
retryholderOnComplete(imageKnifeData: ImageKnifeData) {
|
retryholderOnComplete = (imageKnifeData: ImageKnifeData)=>{
|
||||||
this.retryholderData = imageKnifeData;
|
this.retryholderData = imageKnifeData;
|
||||||
if (this.loadRetryReady) {
|
if (this.loadRetryReady) {
|
||||||
this.retryholderFunc.asyncSuccess(imageKnifeData)
|
this.retryholderFunc.asyncSuccess(imageKnifeData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retryholderOnError(error) {
|
retryholderOnError = (error)=>{
|
||||||
LogUtil.log("重试占位图解析失败 error =" + error)
|
LogUtil.log("重试占位图解析失败 error =" + error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,13 @@ import { FileTypeUtil } from '../../imageknife/utils/FileTypeUtil'
|
||||||
import { ImageKnifeData, ImageKnifeType } from '../ImageKnifeData'
|
import { ImageKnifeData, ImageKnifeType } from '../ImageKnifeData'
|
||||||
import { ParseImageUtil } from '../utils/ParseImageUtil'
|
import { ParseImageUtil } from '../utils/ParseImageUtil'
|
||||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
import { SVGParseImpl,Size } from '../utils/svg/SVGParseImpl'
|
||||||
import { ParseResClient } from '../resourcemanage/ParseResClient'
|
import { ParseResClient } from '../resourcemanage/ParseResClient'
|
||||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||||
import image from '@ohos.multimedia.image'
|
import image from '@ohos.multimedia.image'
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
|
|
||||||
export class ErrorHolderManager {
|
export class ErrorHolderManager<T> {
|
||||||
private options: RequestOption;
|
private options: RequestOption;
|
||||||
|
|
||||||
constructor(option: RequestOption) {
|
constructor(option: RequestOption) {
|
||||||
|
@ -31,16 +32,16 @@ export class ErrorHolderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static execute(option: RequestOption) {
|
static execute(option: RequestOption) {
|
||||||
let manager = new ErrorHolderManager(option);
|
let manager:ErrorHolderManager<ImageKnifeData> = new ErrorHolderManager<ImageKnifeData>(option);
|
||||||
return new Promise(manager.process.bind(manager))
|
return new Promise(manager.process)
|
||||||
.then(option.errorholderOnComplete.bind(option)).catch(option.errorholderOnError.bind(option));
|
.then(option.errorholderOnComplete).catch(option.errorholderOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
process(onComplete, onError) {
|
process = (onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void)=>{
|
||||||
this.displayErrorholder(onComplete, onError);
|
this.displayErrorholder(onComplete, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private displayErrorholder(onComplete, onError) {
|
private displayErrorholder(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void) {
|
||||||
LogUtil.log("displayErrorholder")
|
LogUtil.log("displayErrorholder")
|
||||||
if ((typeof (this.options.errorholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
if ((typeof (this.options.errorholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.errorholderSrc as PixelMap)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.errorholderSrc as PixelMap)
|
||||||
|
@ -51,9 +52,9 @@ export class ErrorHolderManager {
|
||||||
let res = this.options.errorholderSrc as Resource;
|
let res = this.options.errorholderSrc as Resource;
|
||||||
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
||||||
let resourceFetch = new ParseResClient();
|
let resourceFetch = new ParseResClient();
|
||||||
let suc = (arraybuffer) => {
|
let suc = (arraybuffer:ArrayBuffer) => {
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil:FileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
let typeValue:string = fileTypeUtil.getFileType(arraybuffer);
|
||||||
switch (typeValue) {
|
switch (typeValue) {
|
||||||
case SupportFormat.svg:
|
case SupportFormat.svg:
|
||||||
this.svgProcess(onComplete, onError, arraybuffer, typeValue)
|
this.svgProcess(onComplete, onError, arraybuffer, typeValue)
|
||||||
|
@ -78,18 +79,18 @@ export class ErrorHolderManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
private svgProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let svgParseImpl = new SVGParseImpl()
|
let svgParseImpl:SVGParseImpl = new SVGParseImpl()
|
||||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
let size:Size = { width: this.options.size.width, height: this.options.size.height }
|
||||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
onComplete(imageKnifeData)
|
onComplete(imageKnifeData)
|
||||||
}).catch(err => {
|
}).catch((err:BusinessError) => {
|
||||||
onError(err)
|
onError(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
private mediaImageProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let parseImageUtil = new ParseImageUtil()
|
let parseImageUtil = new ParseImageUtil()
|
||||||
let success = (value: PixelMap) => {
|
let success = (value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
|
|
|
@ -20,12 +20,12 @@ import {ImageKnifeData,ImageKnifeType} from "../ImageKnifeData"
|
||||||
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
||||||
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
||||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
import { SVGParseImpl,Size} from '../utils/svg/SVGParseImpl'
|
||||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||||
import resourceManager from '@ohos.resourceManager';
|
import resourceManager from '@ohos.resourceManager';
|
||||||
import image from "@ohos.multimedia.image"
|
import image from "@ohos.multimedia.image"
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
export class PlaceHolderManager {
|
export class PlaceHolderManager<T> {
|
||||||
private options: RequestOption;
|
private options: RequestOption;
|
||||||
|
|
||||||
constructor(option: RequestOption) {
|
constructor(option: RequestOption) {
|
||||||
|
@ -33,16 +33,16 @@ export class PlaceHolderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static execute(option: RequestOption) {
|
static execute(option: RequestOption) {
|
||||||
let manager = new PlaceHolderManager(option);
|
let manager:PlaceHolderManager<ImageKnifeData> = new PlaceHolderManager<ImageKnifeData>(option);
|
||||||
return new Promise(manager.process.bind(manager))
|
return new Promise(manager.process)
|
||||||
.then(option.placeholderOnComplete.bind(option)).catch(option.placeholderOnError.bind(option));
|
.then(option.placeholderOnComplete).catch(option.placeholderOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
process(onComplete, onError) {
|
process = (onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void)=>{
|
||||||
this.displayPlaceholder(onComplete, onError);
|
this.displayPlaceholder(onComplete, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private displayPlaceholder(onComplete, onError) {
|
private displayPlaceholder(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void){
|
||||||
LogUtil.log("displayPlaceholder")
|
LogUtil.log("displayPlaceholder")
|
||||||
if ((typeof (this.options.placeholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
if ((typeof (this.options.placeholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||||
|
@ -53,7 +53,7 @@ export class PlaceHolderManager {
|
||||||
let res = this.options.placeholderSrc as Resource;
|
let res = this.options.placeholderSrc as Resource;
|
||||||
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
||||||
let resourceFetch = new ParseResClient();
|
let resourceFetch = new ParseResClient();
|
||||||
let suc = (arraybuffer) => {
|
let suc = (arraybuffer:ArrayBuffer) => {
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
||||||
switch (typeValue) {
|
switch (typeValue) {
|
||||||
|
@ -82,19 +82,19 @@ export class PlaceHolderManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
private svgProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let svgParseImpl = new SVGParseImpl()
|
let svgParseImpl:SVGParseImpl = new SVGParseImpl()
|
||||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
let size:Size = { width: this.options.size.width, height: this.options.size.height }
|
||||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
onComplete(imageKnifeData)
|
onComplete(imageKnifeData)
|
||||||
}).catch(err => {
|
}).catch((err:BusinessError) => {
|
||||||
onError(err)
|
onError(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
private mediaImageProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let parseImageUtil = new ParseImageUtil()
|
let parseImageUtil:ParseImageUtil = new ParseImageUtil()
|
||||||
let success = (value: PixelMap) => {
|
let success = (value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
onComplete(imageKnifeData)
|
onComplete(imageKnifeData)
|
||||||
|
|
|
@ -20,12 +20,12 @@ import {ImageKnifeData,ImageKnifeType} from "../ImageKnifeData"
|
||||||
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
import {ParseImageUtil} from '../utils/ParseImageUtil'
|
||||||
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
import {ParseResClient} from '../resourcemanage/ParseResClient'
|
||||||
import { SupportFormat } from '../utils/FileTypeUtil'
|
import { SupportFormat } from '../utils/FileTypeUtil'
|
||||||
import { SVGParseImpl } from '../utils/svg/SVGParseImpl'
|
import { SVGParseImpl,Size } from '../utils/svg/SVGParseImpl'
|
||||||
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
import {LogUtil} from '../../imageknife/utils/LogUtil'
|
||||||
import resourceManager from '@ohos.resourceManager';
|
import resourceManager from '@ohos.resourceManager';
|
||||||
import image from "@ohos.multimedia.image"
|
import image from "@ohos.multimedia.image"
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
export class RetryHolderManager {
|
export class RetryHolderManager<T> {
|
||||||
private options: RequestOption;
|
private options: RequestOption;
|
||||||
|
|
||||||
constructor(option: RequestOption) {
|
constructor(option: RequestOption) {
|
||||||
|
@ -33,16 +33,16 @@ export class RetryHolderManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
static execute(option: RequestOption) {
|
static execute(option: RequestOption) {
|
||||||
let manager = new RetryHolderManager(option);
|
let manager:RetryHolderManager<ImageKnifeData> = new RetryHolderManager<ImageKnifeData>(option);
|
||||||
return new Promise(manager.process.bind(manager))
|
return new Promise(manager.process)
|
||||||
.then(option.retryholderOnComplete.bind(option)).catch(option.retryholderOnError.bind(option));
|
.then(option.retryholderOnComplete).catch(option.retryholderOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
process(onComplete, onError) {
|
process = (onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void)=>{
|
||||||
this.displayRetryholder(onComplete, onError);
|
this.displayRetryholder(onComplete, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private displayRetryholder(onComplete, onError) {
|
private displayRetryholder(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void){
|
||||||
LogUtil.log("displayRetryholder")
|
LogUtil.log("displayRetryholder")
|
||||||
if ((typeof (this.options.retryholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
if ((typeof (this.options.retryholderSrc as image.PixelMap).isEditable) == 'boolean') {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, this.options.placeholderSrc as PixelMap)
|
||||||
|
@ -53,7 +53,7 @@ export class RetryHolderManager {
|
||||||
let res = this.options.retryholderSrc as Resource;
|
let res = this.options.retryholderSrc as Resource;
|
||||||
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
if (typeof res.id != 'undefined' && typeof res.id != 'undefined') {
|
||||||
let resourceFetch = new ParseResClient();
|
let resourceFetch = new ParseResClient();
|
||||||
let suc = (arraybuffer) => {
|
let suc = (arraybuffer:ArrayBuffer) => {
|
||||||
let fileTypeUtil = new FileTypeUtil();
|
let fileTypeUtil = new FileTypeUtil();
|
||||||
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
let typeValue = fileTypeUtil.getFileType(arraybuffer);
|
||||||
switch (typeValue) {
|
switch (typeValue) {
|
||||||
|
@ -82,18 +82,18 @@ export class RetryHolderManager {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private svgProcess(onComplete, onError, arraybuffer, typeValue) {
|
private svgProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let svgParseImpl = new SVGParseImpl()
|
let svgParseImpl = new SVGParseImpl()
|
||||||
let size = { width: this.options.size.width, height: this.options.size.height }
|
let size:Size = { width: this.options.size.width, height: this.options.size.height }
|
||||||
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
svgParseImpl.parseSvg(arraybuffer, size).then((value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
onComplete(imageKnifeData)
|
onComplete(imageKnifeData)
|
||||||
}).catch(err => {
|
}).catch( (err:BusinessError) => {
|
||||||
onError(err)
|
onError(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private mediaImageProcess(onComplete, onError, arraybuffer, typeValue) {
|
private mediaImageProcess(onComplete:(value:ImageKnifeData)=>void|PromiseLike<ImageKnifeData>, onError:(reason?:BusinessError|string)=>void, arraybuffer:ArrayBuffer, typeValue:string) {
|
||||||
let parseImageUtil = new ParseImageUtil()
|
let parseImageUtil = new ParseImageUtil()
|
||||||
let success = (value: PixelMap) => {
|
let success = (value: PixelMap) => {
|
||||||
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
let imageKnifeData = ImageKnifeData.createImagePixelMap(ImageKnifeType.PIXELMAP, value)
|
||||||
|
|
|
@ -26,7 +26,7 @@ export interface DataCacheInfo{
|
||||||
path: string,
|
path: string,
|
||||||
key: string
|
key: string
|
||||||
}
|
}
|
||||||
export class AllCacheInfo {
|
export interface AllCacheInfo {
|
||||||
memoryCacheInfo: MemoryCacheInfo
|
memoryCacheInfo: MemoryCacheInfo
|
||||||
resourceCacheInfo: ResourceCacheInfo
|
resourceCacheInfo: ResourceCacheInfo
|
||||||
dataCacheInfo: DataCacheInfo
|
dataCacheInfo: DataCacheInfo
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
export interface IParseImage {
|
export interface IParseImage<T> {
|
||||||
parseImage(imageinfo:ArrayBuffer, onCompleteFunction, onErrorFunction);
|
parseImage:(imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||||
parseImageThumbnail(scale:number, imageinfo:ArrayBuffer, onCompleteFunction, onErrorFunction);
|
parseImageThumbnail:(scale:number, imageinfo:ArrayBuffer, onCompleteFunction:(value:T)=>void | PromiseLike<T>, onErrorFunction:(reason?:BusinessError|string)=>void)=>void;
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ export class FileTypeUtil {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
getFileType(arraybuffer: ArrayBuffer) {
|
getFileType(arraybuffer: ArrayBuffer):string {
|
||||||
let fileType = undefined;
|
let fileType = undefined;
|
||||||
if (arraybuffer == null || arraybuffer == undefined || arraybuffer.byteLength <= this.READ_MIN_LENGTH) {
|
if (arraybuffer == null || arraybuffer == undefined || arraybuffer.byteLength <= this.READ_MIN_LENGTH) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -15,15 +15,15 @@
|
||||||
|
|
||||||
import type {IParseImage} from '../interface/IParseImage'
|
import type {IParseImage} from '../interface/IParseImage'
|
||||||
import image from '@ohos.multimedia.image';
|
import image from '@ohos.multimedia.image';
|
||||||
|
import { BusinessError } from '@ohos.base'
|
||||||
export class ParseImageUtil implements IParseImage {
|
export class ParseImageUtil implements IParseImage<PixelMap> {
|
||||||
parseImage(imageinfo: ArrayBuffer, onCompleteFunction, onErrorFunction) {
|
parseImage(imageinfo: ArrayBuffer, onCompleteFunction:(value:PixelMap)=>void | PromiseLike<PixelMap>, onErrorFunction:(reason?:BusinessError|string)=>void) {
|
||||||
this.parseImageThumbnail(1, imageinfo, onCompleteFunction, onErrorFunction)
|
this.parseImageThumbnail(1, imageinfo, onCompleteFunction, onErrorFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
// scale(0,1)
|
// scale(0,1)
|
||||||
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction, onErrorFunction) {
|
parseImageThumbnail(scale: number, imageinfo: ArrayBuffer, onCompleteFunction:(value:PixelMap)=>void | PromiseLike<PixelMap>, onErrorFunction:(reason?:BusinessError|string)=>void) {
|
||||||
let imageSource = image.createImageSource(imageinfo as any); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
let imageSource:image.ImageSource = image.createImageSource(imageinfo); // 步骤一:文件转为pixelMap 然后变换 给Image组件
|
||||||
imageSource.getImageInfo((err, value) => {
|
imageSource.getImageInfo((err, value) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
onErrorFunction(err);
|
onErrorFunction(err);
|
||||||
|
@ -36,7 +36,7 @@ export class ParseImageUtil implements IParseImage {
|
||||||
'width': wValue
|
'width': wValue
|
||||||
};
|
};
|
||||||
|
|
||||||
let opts = {
|
let opts:image.DecodingOptions = {
|
||||||
editable: true,
|
editable: true,
|
||||||
desiredSize: defaultSize
|
desiredSize: defaultSize
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,8 +14,11 @@
|
||||||
*/
|
*/
|
||||||
import type {IParseSvg} from'./IParseSvg'
|
import type {IParseSvg} from'./IParseSvg'
|
||||||
import {SVGImageView} from '@ohos/svg'
|
import {SVGImageView} from '@ohos/svg'
|
||||||
|
export interface Size{
|
||||||
|
width:number,height:number
|
||||||
|
}
|
||||||
export class SVGParseImpl implements IParseSvg{
|
export class SVGParseImpl implements IParseSvg{
|
||||||
parseSvg(imageinfo: ArrayBuffer,size?:{width:number,height:number}): Promise<PixelMap>{
|
parseSvg(imageinfo: ArrayBuffer,size?:Size): Promise<PixelMap>{
|
||||||
let model = new SVGImageView.SVGImageViewModel();
|
let model = new SVGImageView.SVGImageViewModel();
|
||||||
return model.getSVGPixelMap(new Uint8Array(imageinfo),size);
|
return model.getSVGPixelMap(new Uint8Array(imageinfo),size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue