diff --git a/README_zh.md b/README_zh.md index eaec8d0..a15d2bd 100644 --- a/README_zh.md +++ b/README_zh.md @@ -377,7 +377,7 @@ async function custom(context: Context, src: string | PixelMap | Resource,header | onComplete | (event:EventImage、undefined) => void | 图片成功回调事件(可选) | | onLoadListener | onLoadStart?: (req?: ImageKnifeRequest) => void,onLoadSuccess?: (data: string \| PixelMap \| undefined, imageData: ImageKnifeData, req?: ImageKnifeRequest) => void,onLoadFailed?: (err: string, req?: ImageKnifeRequest) => void,onLoadCancel?: (res: string, req?: ImageKnifeRequest) => void | 监听图片加载成功与失败 | | downsampleOf | DownsampleStrategy | 降采样(可选) | -| httpOption | httpRequestOption | 网络请求配置(可选) | +| httpOption | HttpRequestOption | 网络请求配置(可选) | ### 降采样类型 | 类型 | 相关描述 | diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 664eb38..b3ab212 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -82,6 +82,12 @@ struct Index { }); }) + Button($r('app.string.Test_LocalImageShow')).margin({top:10}).onClick(()=>{ + router.push({ + uri: 'pages/LocalImage', + + }); + }) Button($r('app.string.Test_custom_download')).margin({top:10}).onClick(()=>{ router.push({ uri: 'pages/TestSetCustomImagePage', diff --git a/entry/src/main/ets/pages/LocalImage.ets b/entry/src/main/ets/pages/LocalImage.ets new file mode 100644 index 0000000..bd8e8df --- /dev/null +++ b/entry/src/main/ets/pages/LocalImage.ets @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2024 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 { ImageKnifeComponent } from '@ohos/libraryimageknife'; +import fs from '@ohos.file.fs'; + +@Entry +@Component +struct LocalImage { + scroller: Scroller = new Scroller; + localFile: string = getContext(this).filesDir + '/icon.png' + + aboutToAppear(): void { + // 拷贝本地文件 + let icon: Uint8Array = getContext(this).resourceManager.getMediaContentSync($r('app.media.startIcon')); + let file = fs.openSync(this.localFile, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); + fs.writeSync(file.fd, icon.buffer); + fs.fsyncSync(file.fd); + fs.closeSync(file); + } + + build() { + Scroll(this.scroller) { + Column() { + Text($r('app.string.local_r_file')) + .fontSize(30) + .fontWeight(FontWeight.Bold) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: $r('app.media.startIcon'), + objectFit: ImageFit.Contain + } + }).width(100).height(100) + Text($r('app.string.local_rawfile')) + .fontSize(30) + .fontWeight(FontWeight.Bold) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: $rawfile('image/startIcon.png'), + objectFit: ImageFit.Contain + } + }).width(100).height(100) + Text($r('app.string.Under_context_file')) + .fontSize(30) + .fontWeight(FontWeight.Bold) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: this.localFile, + objectFit: ImageFit.Contain + } + }).width(100).height(100) + Text($r('app.string.local_other_module')) + .fontSize(30) + .fontWeight(FontWeight.Bold) + ImageKnifeComponent({ + imageKnifeOption: { + loadSrc: $r('[sharedlibrary].media.startIcon'), + objectFit: ImageFit.Contain + } + }).width(100).height(100) + } + .width('100%') + } + .height('100%') + } +} + diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index b246b61..ed78ad0 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -40,6 +40,10 @@ "name": "Test_SingleImage", "value": "SingleImage" }, + { + "name": "Test_LocalImageShow", + "value": "LocalImageShow" + }, { "name": "Test_custom_download", "value": "Global custom download" @@ -140,10 +144,26 @@ "name": "Local_SVG", "value": "Local SVG image" }, + { + "name": "local_r_file", + "value": "Local $r file" + }, + { + "name": "local_rawfile", + "value": "Local rawfile" + }, { "name": "Under_context_file", "value": "Files under context file" }, + { + "name": "local_other_module", + "value": "Local other module" + }, + { + "name": "in_other_module", + "value": "in other module" + }, { "name": "Network_images", "value": "Network images" diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index c8be797..54d8b21 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -40,6 +40,7 @@ "pages/DownSamplePage", "pages/AutoImageFit", "pages/SingleImageCallBack", - "pages/MultipleImageCallBack" + "pages/MultipleImageCallBack", + "pages/LocalImage" ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json deleted file mode 100644 index 4d62c27..0000000 --- a/entry/src/main/resources/en_US/element/string.json +++ /dev/null @@ -1,380 +0,0 @@ -{ - "string": [ - { - "name": "module_desc", - "value": "module description" - }, - { - "name": "EntryAbility_desc", - "value": "description" - }, - { - "name": "EntryAbility_label", - "value": "label" - }, - { - "name": "app_permission_WRITE_IMAGEVIDEO", - "value": "获取写入媒体资源权限" - }, - { - "name": "app_permission_READ_IMAGEVIDEO", - "value": "获取读媒体资源权限" - }, - { - "name": "Test_ImageAnimator", - "value": "Test ImageAnimator component" - }, - { - "name": "Test_multiple_images", - "value": "Test loading multiple identical images" - }, - { - "name": "Test_Task_error", - "value": "Test placeholder map Task error" - }, - { - "name": "Test_HSP", - "value": "Test HSP scene preloading" - }, - { - "name": "Test_SingleImage", - "value": "SingleImage" - }, - { - "name": "Test_custom_download", - "value": "Global custom download" - }, - { - "name": "Multiple_images", - "value": "Multiple images" - }, - { - "name": "Display_long_image", - "value": "Display long image" - }, - { - "name": "Image_scaling", - "value": "Image scaling" - }, - { - "name": "Message_list", - "value": "Message list" - }, - { - "name": "Custom_cache_key", - "value": "Custom cache key" - }, - { - "name": "Preloading_images_to_cache", - "value": "Preloading images to file cache" - }, - { - "name": "Retrieve_image_display_from_cache", - "value": "Retrieve image display from cache" - }, - { - "name": "Test_single_request_header", - "value": "Test a single request header" - }, - { - "name": "Test_write_cache_strategy", - "value": "Test write cache strategy" - }, - { - "name": "Image_Transformation", - "value": "Image Transformation" - }, - { - "name": "Different_ObjectFit", - "value": "Different ObjectFit" - }, - { - "name": "Test_image_loading_success_or_failure_events", - "value": "Test image loading success/failure events" - }, - { - "name": "Test_removing_image_cache_interface", - "value": "Test removing image cache interface" - }, - { - "name": "Test_error_image_display", - "value": "Test error image display" - }, - { - "name": "Test_media_URL", - "value": "Test media URL" - }, - { - "name": "Display_the_first_frame", - "value": "Display the first frame of the animation" - }, - { - "name": "Display_the_last_frame", - "value": "Display the last frame of the animation" - }, - { - "name": "Play", - "value": "Play" - }, - { - "name": "Pause", - "value": "Pause" - }, - { - "name": "Stop", - "value": "Stop" - }, - { - "name": "Infinite_loop", - "value": "Infinite loop" - }, - { - "name": "Play_once", - "value": "Play once" - }, - { - "name": "Play_twice", - "value": "Play twice" - }, - { - "name": "Local_SVG", - "value": "Local SVG image" - }, - { - "name": "Under_context_file", - "value": "Files under context file" - }, - { - "name": "Network_images", - "value": "Network images" - }, - { - "name": "Custom_network_download", - "value": "Custom network download" - }, - { - "name": "PixelMap_loads_images", - "value": "PixelMap loads images" - }, - { - "name": "Enlarge", - "value": "Enlarge" - }, - { - "name": "Reduce", - "value": "Reduce" - }, - { - "name": "Click_on_add", - "value": "Click on the size to add 50" - }, - { - "name": "Click_on_reduce", - "value": "Click to reduce size by 50" - }, - { - "name": "The_key_fixed_1", - "value": "The key is fixed at 1" - }, - { - "name": "The_key_changes_timestamp", - "value": "Key changes every time: timestamp" - }, - { - "name": "Load", - "value": "Load" - }, - { - "name": "Preloading_images_to_file_cache_using_URL", - "value": "Preloading images to file cache using URL" - }, - { - "name": "Preloading_images_to_file_cache_using_option", - "value": "Preloading images to file cache using option" - }, - { - "name": "Load_image_offline_after_preloading", - "value": "Load image (can be loaded offline after preloading)" - }, - { - "name": "Preloading_GIF", - "value": "Preloading GIF" - }, - { - "name": "Retrieve_GIF_from_memory", - "value": "Retrieve GIF from memory cache" - }, - { - "name": "Retrieve_GIF_from_disk", - "value": "Retrieve GIF from disk cache" - }, - { - "name": "Preloading_static_images", - "value": "Preloading static images" - }, - { - "name": "Retrieve_images_from_memory", - "value": "Retrieve images from memory cache" - }, - { - "name": "Retrieve_images_from_disk", - "value": "Retrieve images from memory disk" - }, - { - "name": "Write_memory_and_file", - "value": "Write to memory and file cache" - }, - { - "name": "Write_memory", - "value": "Write to memory cache" - }, - { - "name": "Write_file", - "value": "Write to file cache" - }, - { - "name": "Main_image_Fill", - "value": "Main image Fill Stretch Fill" - }, - { - "name": "Maintain_proportion_filling", - "value": "Maintain proportion filling in the placeholder map 'Include'" - }, - { - "name": "Error_graph_None", - "value": "Error graph None remains unchanged" - }, - { - "name": "Test_failure_success", - "value": "Test failure/success" - }, - { - "name": "Custom_download_failed", - "value": "Custom download failed" - }, - { - "name": "Retrieve_media_gallery", - "value": "Retrieve the URI of the media gallery and display it using ImageKnife" - }, - { - "name": "Click_load_Uri", - "value": "Click to load Uri and display" - }, - { - "name": "Delete_all_caches", - "value": "Delete all caches" - }, - { - "name": "Delete_all_memory_caches", - "value": "Delete all memory caches" - }, - { - "name": "Delete_all_file_caches", - "value": "Delete all file caches" - }, - { - "name": "Delete_all_custom_memory_caches", - "value": "Delete all custom memory caches" - }, - { - "name": "Delete_all_custom_file_caches", - "value": "Delete all custom file caches" - }, - { - "name": "Blur_effect", - "value": "Blur effect" - }, - { - "name": "Highlighting_effect", - "value": "Highlighting effect" - }, - { - "name": "Ashing_effect", - "value": "Ashing effect" - }, - { - "name": "Inverse_effect", - "value": "Inverse effect" - }, - { - "name": "Animation_filter_effect", - "value": "Animation filter effect" - }, - { - "name": "Crop_circular_effect", - "value": "Crop circular effect" - }, - { - "name": "Crop_circular_with_border_effect", - "value": "Crop circular with border effect" - }, - { - "name": "Contrast_effect", - "value": "Contrast effect" - }, - { - "name": "Black_ink_filtering_effect", - "value": "Black ink filtering effect" - }, - { - "name": "Rotate", - "value": "Rotate" - }, - { - "name": "Corners", - "value": "Corners" - }, - { - "name": "Kuwahara_Filter_effect", - "value": "Kuwahara filter effect" - }, - { - "name": "Pixelated_Filter_effect", - "value": "Pixelated filtering effect" - }, - { - "name": "Sketch_Filter_effect", - "value": "Sketch Filter effect" - }, - { - "name": "Distortion_Filter_effect", - "value": "Distortion Filter effect" - }, - { - "name": "Decorative_Filter_effect", - "value": "Decorative Filter effect" - }, - { - "name": "Square_cutting_effect", - "value": "Square cutting effect" - }, - { - "name": "Top_cutting_effect", - "value": "Top cutting effect" - }, - { - "name": "Middle_cutting_effect", - "value": "Middle cutting effect" - }, - { - "name": "Bottom_cutting_effect", - "value": "Bottom cutting effect" - }, - { - "name": "Mask_effect", - "value": "Mask effect" - }, - { - "name": "TIPS", - "value": "Please shut down the network first and ensure that there is no cache of images from this network in the test failure scenario locally" - }, - { - "name": "Network_reload", - "value": "Network recovery reload" - }, - { - "name": "preloading_prefetch", - "value": "Dynamic preloading prefetch" - } - ] -} \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/image/startIcon.png b/entry/src/main/resources/rawfile/image/startIcon.png new file mode 100644 index 0000000..366f764 Binary files /dev/null and b/entry/src/main/resources/rawfile/image/startIcon.png differ diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index cea7589..35f0c99 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -40,6 +40,10 @@ "name": "Test_SingleImage", "value": "单个图片使用" }, + { + "name": "Test_LocalImageShow", + "value": "本地图片显示" + }, { "name": "Test_custom_download", "value": "全局自定义下载" @@ -136,9 +140,21 @@ "name": "Local_SVG", "value": "本地资源SVG图片" }, + { + "name": "local_r_file", + "value": "本地$r文件" + }, + { + "name": "local_rawfile", + "value": "本地rawfile文件" + }, { "name": "Under_context_file", - "value": "本地context files下文件" + "value": "本地沙箱路径文件" + }, + { + "name": "local_other_module", + "value": "本地其他模块文件" }, { "name": "Network_images", diff --git a/library/index.ets b/library/index.ets index 28fc8d8..65d243d 100644 --- a/library/index.ets +++ b/library/index.ets @@ -18,7 +18,10 @@ export { ImageKnifeAnimatorComponent } from './src/main/ets/components/ImageKnif export { ImageKnife } from './src/main/ets/ImageKnife' -export { ImageKnifeOption , AnimatorOption,httpRequestOption,HeaderOptions } from './src/main/ets/model/ImageKnifeOption' +export { ImageKnifeOption, + AnimatorOption, + HttpRequestOption, + HeaderOptions } from './src/main/ets/model/ImageKnifeOption' export { ImageKnifeRequest } from './src/main/ets/model/ImageKnifeRequest' diff --git a/library/src/main/ets/model/ImageKnifeOption.ets b/library/src/main/ets/model/ImageKnifeOption.ets index 2c1ba36..00f63ba 100644 --- a/library/src/main/ets/model/ImageKnifeOption.ets +++ b/library/src/main/ets/model/ImageKnifeOption.ets @@ -45,7 +45,7 @@ export class AnimatorOption { onRepeat?:()=>void } -export interface httpRequestOption { +export interface HttpRequestOption { caPath?: string // 自定义证书路径 connectTimeout?: number // 连接超时 readTimeout?: number // 读取超时 @@ -82,7 +82,7 @@ export class ImageKnifeOption { drawingColorFilter?: ColorFilter | drawing.ColorFilter downsampleOf?: DownsampleStrategy // 降采样 // 自定义证书路径 - httpOption?: httpRequestOption + httpOption?: HttpRequestOption constructor() { } diff --git a/sharedlibrary/Index.ets b/sharedlibrary/Index.ets index d426419..f5243ad 100644 --- a/sharedlibrary/Index.ets +++ b/sharedlibrary/Index.ets @@ -22,7 +22,7 @@ export { ImageKnifeComponent,ImageKnifeAnimatorComponent } from '@ohos/imageknif export { ImageKnife } from '@ohos/imageknife' -export { ImageKnifeOption,AnimatorOption,httpRequestOption,HeaderOptions } from '@ohos/imageknife' +export { ImageKnifeOption, AnimatorOption, HttpRequestOption, HeaderOptions } from '@ohos/imageknife' export { DownsampleStrategy } from "@ohos/imageknife"