parent
8c15816eee
commit
a7c8d54324
|
@ -17,8 +17,6 @@ import router from '@system.router';
|
|||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
|
||||
|
||||
aboutToAppear(): void {
|
||||
|
||||
}
|
||||
|
@ -26,73 +24,78 @@ struct Index {
|
|||
build() {
|
||||
|
||||
Column() {
|
||||
Button("单个图片使用").onClick(()=>{
|
||||
Button("单个图片使用").onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/SingleImage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("多图 + LazyForEach").margin({top:10}).onClick(()=>{
|
||||
Button("下采样").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: "pages/DownSamplePage",
|
||||
});
|
||||
})
|
||||
Button("多图 + LazyForEach").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/ManyPhotoShowPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("多图 + reuse + LazyForeach").margin({top:10}).onClick(()=>{
|
||||
Button("多图 + reuse + LazyForeach").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/UserPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("长图显示").margin({top:10}).onClick(()=>{
|
||||
Button("长图显示").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/LongImagePage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("缩放图片").margin({top:10}).onClick(()=>{
|
||||
Button("缩放图片").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TransformPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("消息+List").margin({top:10}).onClick(()=>{
|
||||
Button("消息+List").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestImageFlash',
|
||||
|
||||
});
|
||||
})
|
||||
Button("自定义缓存key").margin({top:10}).onClick(()=>{
|
||||
Button("自定义缓存key").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/SignatureTestPage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("预加载图片到文件缓存").margin({top:10}).onClick(()=>{
|
||||
Button("预加载图片到文件缓存").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestPrefetchToFileCache',
|
||||
|
||||
});
|
||||
})
|
||||
Button("从缓存获取图片显示").margin({top:10}).onClick(()=>{
|
||||
Button("从缓存获取图片显示").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestIsUrlExist',
|
||||
|
||||
});
|
||||
})
|
||||
Button("测试单个请求头").margin({top:10}).onClick(()=>{
|
||||
Button("测试单个请求头").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestHeader',
|
||||
|
||||
});
|
||||
})
|
||||
Button("测试写入缓存策略").margin({top:10}).onClick(()=>{
|
||||
Button("测试写入缓存策略").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/TestWriteCacheStage',
|
||||
|
||||
});
|
||||
})
|
||||
Button("图片变换").margin({top:10}).onClick(()=>{
|
||||
Button("图片变换").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/ImageTransformation',
|
||||
|
||||
|
@ -100,7 +103,7 @@ struct Index {
|
|||
|
||||
})
|
||||
|
||||
Button("不同的ObjectFit").margin({top:10}).onClick(()=>{
|
||||
Button("不同的ObjectFit").margin({ top: 10 }).onClick(() => {
|
||||
router.push({
|
||||
uri: 'pages/ObjectFitPage',
|
||||
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
"pages/TestHeader",
|
||||
"pages/ImageTransformation",
|
||||
"pages/ObjectFitPage",
|
||||
"pages/TestWriteCacheStage",
|
||||
"pages/LoadStatePage",
|
||||
"pages/TestRemoveCache"
|
||||
"pages/TestRemoveCache",
|
||||
"pages/TestWriteCacheStage",
|
||||
"pages/DownSamplePage"
|
||||
]
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "4.1.2"
|
||||
},
|
||||
"execution": {
|
||||
// "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
export default class BuildProfile {
|
||||
static readonly HAR_VERSION = '3.0.0-rc.0';
|
||||
static readonly HAR_VERSION = '3.0.0-rc.4';
|
||||
static readonly BUILD_MODE_NAME = 'debug';
|
||||
static readonly DEBUG = true;
|
||||
static readonly TARGET_NAME = 'default';
|
||||
}
|
|
@ -22,4 +22,6 @@ export { BrightnessTransformation } from './src/main/ets/transform/BrightnessTra
|
|||
|
||||
export { BlurTransformation } from './src/main/ets/transform/BlurTransformation'
|
||||
|
||||
export { DownsampleStrategy } from './src/main/ets/downsampling/DownsampleStartegy'
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@ import {
|
|||
RequestJobRequest
|
||||
} from './model/ImageKnifeData'
|
||||
import { combineArrayBuffers } from './model/utils';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { Downsampler } from './downsampling/Downsampler'
|
||||
import { DownsampleStrategy } from './downsampling/DownsampleStartegy';
|
||||
|
||||
export class ImageKnifeDispatcher {
|
||||
// 最大并发
|
||||
|
@ -144,7 +147,12 @@ export class ImageKnifeDispatcher {
|
|||
.isFileCacheInit() ? currentRequest.imageKnifeOption.writeCacheStrategy : CacheStrategy.Memory, // 未初始化文件缓存时,不写文件缓存
|
||||
engineKey: this.engineKey,
|
||||
signature: currentRequest.imageKnifeOption.signature,
|
||||
requestSource
|
||||
requestSource,
|
||||
targetWidth: currentRequest.componentWidth,
|
||||
targetHeight: currentRequest.componentHeight,
|
||||
downsampType: currentRequest.imageKnifeOption.downsampling,
|
||||
autoResize:currentRequest.imageKnifeOption.autoResize
|
||||
|
||||
}
|
||||
// 启动线程下载和解码主图
|
||||
let task = new taskpool.Task(requestJob, request)
|
||||
|
@ -404,7 +412,6 @@ async function requestJob(request: RequestJobRequest): Promise<RequestJobResult
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (resBuf == undefined) {
|
||||
return {
|
||||
pixelMap: undefined,
|
||||
|
@ -418,7 +425,6 @@ async function requestJob(request: RequestJobRequest): Promise<RequestJobResult
|
|||
let typeValue = fileTypeUtil.getFileType(resBuf);
|
||||
if (typeValue === 'gif' || typeValue === 'webp') {
|
||||
let base64Help = new util.Base64Helper()
|
||||
|
||||
let base64str = "data:image/" + typeValue + ";base64," + base64Help.encodeToStringSync(new Uint8Array(resBuf))
|
||||
return {
|
||||
pixelMap: base64str,
|
||||
|
@ -426,10 +432,19 @@ async function requestJob(request: RequestJobRequest): Promise<RequestJobResult
|
|||
fileKey: fileKey
|
||||
};
|
||||
}
|
||||
|
||||
let autoResizes = request.autoResize
|
||||
let imageSource: image.ImageSource = image.createImageSource(resBuf);
|
||||
let decodingOptions: image.DecodingOptions = {
|
||||
let imageInfo = await imageSource.getImageInfo()
|
||||
let a = new Downsampler().calculateScaling(typeValue, imageInfo.size.width, imageInfo.size.height, request.targetWidth,
|
||||
request.targetHeight, request.downsampType,autoResizes)
|
||||
let decodingOptions: image.DecodingOptions = request.downsampType === DownsampleStrategy.NONE ? {
|
||||
editable: true,
|
||||
} : {
|
||||
editable: true,
|
||||
desiredSize: {
|
||||
width: a.targetWidth,
|
||||
height: a.targetHeight
|
||||
}
|
||||
}
|
||||
|
||||
let resPixelmap: PixelMap | undefined = undefined
|
||||
|
|
|
@ -13,14 +13,16 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
import taskpool from '@ohos.taskpool';
|
||||
import common from '@ohos.app.ability.common'
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { CacheStrategy } from './model/ImageKnifeData';
|
||||
import { PixelMapTransformation } from './transform/PixelMapTransformation';
|
||||
import { DownsampleStrategy } from './downsampling/DownsampleStartegy';
|
||||
|
||||
export interface HeaderOptions {
|
||||
key: string;
|
||||
value: Object;
|
||||
}
|
||||
|
||||
@Observed
|
||||
export class ImageKnifeOption {
|
||||
// 主图资源
|
||||
|
@ -29,31 +31,22 @@ export class ImageKnifeOption {
|
|||
placeholderSrc?: string | PixelMap | Resource;
|
||||
// 失败占位图
|
||||
errorholderSrc?: string | PixelMap | Resource;
|
||||
|
||||
headerOption?: Array<HeaderOptions>;
|
||||
|
||||
// 自定义缓存关键字
|
||||
signature?: string;
|
||||
|
||||
// 主图填充效果
|
||||
objectFit?: ImageFit
|
||||
|
||||
// 占位图填充效果
|
||||
placeholderObjectFit?: ImageFit
|
||||
|
||||
// 错误图填充效果
|
||||
errorholderObjectFit?: ImageFit
|
||||
|
||||
customGetImage?: (context: Context, src: string | PixelMap | Resource) => Promise<ArrayBuffer | undefined>
|
||||
|
||||
border?: BorderOptions
|
||||
// 缓存策略
|
||||
writeCacheStrategy?: CacheStrategy
|
||||
// 仅使用缓存加载数据
|
||||
onlyRetrieveFromCache?: boolean = false;
|
||||
|
||||
priority? : taskpool.Priority = taskpool.Priority.LOW
|
||||
|
||||
priority?: taskpool.Priority = taskpool.Priority.LOW
|
||||
context?: common.UIAbilityContext;
|
||||
|
||||
progressListener?: (progress: number)=>void;
|
||||
|
@ -61,6 +54,11 @@ export class ImageKnifeOption {
|
|||
transformation?: PixelMapTransformation
|
||||
onLoadListener?: OnLoadCallBack | undefined;
|
||||
|
||||
progressListener?: (progress: number) => void;
|
||||
transformation?: PixelMapTransformation;
|
||||
// 下采样
|
||||
downsampling?: DownsampleStrategy = DownsampleStrategy.NONE
|
||||
autoResize?:boolean
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import { ImageKnifeOption } from './ImageKnifeOption';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { ImageKnifeRequestSource } from './model/ImageKnifeData';
|
||||
|
||||
import { DownsampleStrategy } from './downsampling/DownsampleStartegy';
|
||||
|
||||
export class ImageKnifeRequest {
|
||||
requestState: ImageKnifeRequestState = ImageKnifeRequestState.PROGRESS
|
||||
|
@ -25,20 +25,29 @@ export class ImageKnifeRequest {
|
|||
context: common.UIAbilityContext
|
||||
ImageKnifeRequestCallback: ImageKnifeRequestCallback
|
||||
componentVersion: number = 0
|
||||
headers: Map<string,Object> = new Map<string,Object>()
|
||||
headers: Map<string, Object> = new Map<string, Object>()
|
||||
downsampType?: DownsampleStrategy
|
||||
autoResizes?:boolean
|
||||
|
||||
constructor(option: ImageKnifeOption,
|
||||
uIAbilityContext: common.UIAbilityContext,
|
||||
width: number,
|
||||
height: number,
|
||||
version: number,
|
||||
ImageKnifeRequestCallback: ImageKnifeRequestCallback) {
|
||||
ImageKnifeRequestCallback: ImageKnifeRequestCallback,
|
||||
downsampType?: DownsampleStrategy,
|
||||
autoResizes?:boolean
|
||||
) {
|
||||
this.imageKnifeOption = option
|
||||
this.context = uIAbilityContext
|
||||
this.componentWidth = width
|
||||
this.componentHeight = height
|
||||
this.componentVersion = version
|
||||
this.ImageKnifeRequestCallback = ImageKnifeRequestCallback
|
||||
this.downsampType = downsampType
|
||||
this.autoResizes = autoResizes
|
||||
}
|
||||
|
||||
// RequestOption调用header对于的方法
|
||||
addHeader(key: string, value: Object) {
|
||||
this.headers.set(key, value);
|
||||
|
@ -63,5 +72,5 @@ export enum ImageKnifeRequestState {
|
|||
|
||||
|
||||
export interface ImageKnifeRequestCallback {
|
||||
showPixelMap: (version: number, pixelMap: PixelMap | string , requestSource: ImageKnifeRequestSource) => void;
|
||||
showPixelMap: (version: number, pixelMap: PixelMap | string, requestSource: ImageKnifeRequestSource) => void;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import common from '@ohos.app.ability.common';
|
|||
import { ImageKnife } from '../ImageKnife';
|
||||
import { LogUtil } from '../utils/LogUtil';
|
||||
import { ImageKnifeRequestSource } from '../model/ImageKnifeData';
|
||||
import { Downsampler } from '../downsampling/Downsampler';
|
||||
|
||||
@Component
|
||||
export struct ImageKnifeComponent {
|
||||
|
@ -33,6 +34,8 @@ export struct ImageKnifeComponent {
|
|||
private currentHeight: number = 0
|
||||
private componentVersion: number = 0
|
||||
private currentContext: common.UIAbilityContext | undefined = undefined
|
||||
private targetHeight: number =0
|
||||
private targetWidth: number =0
|
||||
|
||||
aboutToAppear(): void {
|
||||
//闪动问题失效,注释相应代码后续修复
|
||||
|
@ -82,7 +85,10 @@ export struct ImageKnifeComponent {
|
|||
ImageKnife.getInstance().execute(this.getRequest(this.currentWidth, this.currentHeight))
|
||||
}
|
||||
}
|
||||
})
|
||||
}).sourceSize({
|
||||
width:250,
|
||||
height:250
|
||||
})
|
||||
}
|
||||
|
||||
watchImageKnifeOption() {
|
||||
|
@ -116,8 +122,9 @@ export struct ImageKnifeComponent {
|
|||
}
|
||||
this.pixelMap = pixelMap
|
||||
if (typeof this.pixelMap !== 'string') {
|
||||
let info =await this.pixelMap.getImageInfo()
|
||||
//图片自适应处理
|
||||
if (this.imageKnifeOption.objectFit === ImageFit.Auto) {
|
||||
let info = await this.pixelMap.getImageInfo()
|
||||
|
||||
this.adaptiveWidth = this.currentWidth
|
||||
this.adaptiveHeight = info.size.height * this.currentWidth / info.size.width
|
||||
|
|
|
@ -17,6 +17,7 @@ import { ImageKnifeRequest } from '../ImageKnifeRequest'
|
|||
import { IEngineKey } from '../key/IEngineKey'
|
||||
import { PixelMapTransformation } from '../transform/PixelMapTransformation'
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { DownsampleStrategy} from '../downsampling/DownsampleStartegy'
|
||||
|
||||
export interface ImageKnifeData {
|
||||
source: PixelMap | string,
|
||||
|
@ -60,7 +61,10 @@ export interface RequestJobResult {
|
|||
fileKey: string
|
||||
loadFail?: string,
|
||||
}
|
||||
|
||||
export interface targetCcaleType {
|
||||
width: number,
|
||||
height: number
|
||||
}
|
||||
/**
|
||||
* request子线程处理时的请求参数
|
||||
*/
|
||||
|
@ -76,5 +80,9 @@ export interface RequestJobRequest {
|
|||
writeCacheStrategy?: CacheStrategy
|
||||
signature?: string
|
||||
engineKey: IEngineKey
|
||||
targetWidth:number
|
||||
targetHeight: number
|
||||
downsampType?:DownsampleStrategy
|
||||
autoResize?:boolean
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue