Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
chenquansheng
2024-11-08 15:50:22 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5001ccf3de5da215fbf78b6df8bc2c9970bf01b9
5001ccf3
1 parent
873478d7
fix |> 修复稿件详情查看大图缺少图片缓存的问题
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
2 deletions
sight_harmony/features/wdComponent/src/main/ets/components/MultiPictureDetailItemComponent.ets
sight_harmony/features/wdComponent/src/main/ets/components/MultiPictureDetailItemComponent.ets
View file @
5001ccf
...
...
@@ -7,8 +7,10 @@ import { WindowSizeManager } from '../utils/Managers';
import { runWithAnimation } from '../utils/FuncUtils';
import { PhotoListBean } from 'wdBean/Index';
import { router } from '@kit.ArkUI';
import {
taskpoo
l } from '@kit.ArkTS';
import {
buffer, taskpool,uti
l } from '@kit.ArkTS';
import { httpRequest } from '../utils/httpRequest';
import { ImageKnifeComponent } from '@ohos/imageknife';
import { Logger,SPHelper } from 'wdKit';
const TAG = 'MultiPictureDetailItemComponent';
...
...
@@ -50,10 +52,32 @@ export struct MultiPictureDetailItemComponent {
@State currentOffset: number = 0
@Consume duration: number
windowSizeManager: WindowSizeManager = new WindowSizeManager();
private picPathKey:string = ''
async aboutToAppear() {
aboutToAppear() {
this.imageUri = this.MultiPictureDetailItem.picPath
let lastIndexOfSlash = this.imageUri.lastIndexOf('/')
let lastIndexOfDot = this.imageUri.lastIndexOf('.')
let resultString = ''
if (lastIndexOfSlash != -1 && lastIndexOfDot != -1 && lastIndexOfDot >lastIndexOfSlash ) {
resultString = this.imageUri.substring(lastIndexOfSlash+1,lastIndexOfDot)
}
this.picPathKey = resultString;
let base64Str = SPHelper.default.getSync(this.picPathKey, '') as string
let base64StartIndex = base64Str.indexOf("base64,") + "base64,".length;
base64Str = base64Str.substring(base64StartIndex);
if (base64Str.length > 0) {
let helper = new util.Base64Helper();
let buffer: ArrayBuffer = helper.decodeSync(base64Str, util.Type.MIME).buffer as ArrayBuffer;
let imageSource = image.createImageSource(buffer);
let opts: image.DecodingOptions = { editable: true };
this.imagePixelMap = await imageSource.createPixelMap(opts);
} else {
// 通过任务池(taskpool)从网络下载图片资源
taskpool.execute(getPicture, this.imageUri).then((res) => {
const imgBuffer = res as ArrayBuffer
...
...
@@ -61,7 +85,21 @@ export struct MultiPictureDetailItemComponent {
this.transcodePixelMap(imgBuffer);
})
}
}
async saveImage(data: image.PixelMap){
if (this.picPathKey.length > 0) {
// 转换成base64
const imagePackerApi: image.ImagePacker = image.createImagePacker();
let packOpts: image.PackingOption = { format: 'image/jpeg', quality: 100 };
imagePackerApi.packing(data, packOpts).then((data: ArrayBuffer) => {
let buf: buffer.Buffer = buffer.from(data);
let base64 = 'data:image/jpeg;base64,' + buf.toString('base64', 0, buf.length);
SPHelper.default.saveSync(this.picPathKey,base64)
})
}
}
/**
* 使用createPixelMap将ArrayBuffer类型的图片装换为PixelMap类型
...
...
@@ -97,6 +135,7 @@ export struct MultiPictureDetailItemComponent {
});
imageSource.createPixelMap().then((data: image.PixelMap) => {
this.imagePixelMap = data;
this.saveImage(data);
}).catch((err: BusinessError) => {
console.error(`[error][createPixelMap]${err.message}`);
});
...
...
Please
register
or
login
to post a comment