diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index f14114bfed5242a017da847472c02a1be7d50cc0..a75655217377338121911d545136feaf7de912e3 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -27,14 +27,20 @@ class CompressedImageInfo { imageByteLength: number = 0; } -async function compressedImage(sourcePixelMap: image.PixelMap, maxCompressedImageSize: number): Promise { +async function compressedImage(sourcePixelMap: image.PixelMap, + maxCompressedImageSize: number): Promise { const imagePackerApi = image.createImagePacker(); const IMAGE_QUALITY = 0; const packOpts: image.PackingOption = { format: "image/jpeg", quality: IMAGE_QUALITY }; - let compressedImageData: ArrayBuffer = await imagePackerApi.packToData(sourcePixelMap, packOpts); + let compressedImageData: ArrayBuffer = await imagePackerApi.packToData(sourcePixelMap, packOpts) + .catch((error: BusinessError) => { + hilog.error(0x0000, TAG, `releaseVideo catch error, code: ${error.code}, message: ${error.message}`); + return new ArrayBuffer(0); + }); const maxCompressedImageByte = maxCompressedImageSize * CommonConstants.BYTE_CONVERSION; if (maxCompressedImageByte > compressedImageData.byteLength) { - compressedImageData = await packingImage(compressedImageData, sourcePixelMap, IMAGE_QUALITY, maxCompressedImageByte); + compressedImageData = + await packingImage(compressedImageData, sourcePixelMap, IMAGE_QUALITY, maxCompressedImageByte); } else { let imageScale = 1; const REDUCE_SCALE = CommonConstants.REDUCE_SCALE; @@ -55,12 +61,15 @@ async function compressedImage(sourcePixelMap: image.PixelMap, maxCompressedImag async function packing(sourcePixelMap: image.PixelMap, imageQuality: number): Promise { const imagePackerApi = image.createImagePacker(); const packOpts: image.PackingOption = { format: "image/jpeg", quality: imageQuality }; - const data: ArrayBuffer = await imagePackerApi.packToData(sourcePixelMap, packOpts); + const data: ArrayBuffer = await imagePackerApi.packToData(sourcePixelMap, packOpts).catch((error: BusinessError) => { + hilog.error(0x0000, TAG, `releaseVideo catch error, code: ${error.code}, message: ${error.message}`); + return new ArrayBuffer(0); + }); return data; } async function packingImage(compressedImageData: ArrayBuffer, sourcePixelMap: image.PixelMap, - imageQuality: number, maxCompressedImageByte: number): Promise { + imageQuality: number, maxCompressedImageByte: number): Promise { const packingArray: number[] = []; const DICHOTOMY_ACCURACY = CommonConstants.DICHOTOMY_ACCURACY; for (let i = 0; i <= CommonConstants.PICTURE_QUALITY_MAX; i += DICHOTOMY_ACCURACY) { @@ -99,12 +108,12 @@ async function saveImage(compressedImageData: ArrayBuffer): Promise