update entry/src/main/ets/pages/compressPage.ets.

语义化命名 compressAsyncRecource -> compressAsyncResource,cropressResource -> compressResource

Signed-off-by: Megasu <megasu@qq.com>
This commit is contained in:
Megasu 2024-03-20 03:54:01 +00:00 committed by Gitee
parent ca53509ebc
commit 4b14c76cbd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 57 additions and 35 deletions

View File

@ -12,38 +12,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {ImageKnife} from '@ohos/libraryimageknife'
import {OnRenameListener} from '@ohos/libraryimageknife'
import {OnCompressListener} from '@ohos/libraryimageknife'
import {ImageKnifeGlobal} from '@ohos/libraryimageknife'
import { ImageKnife, ImageKnifeGlobal, OnCompressListener, OnRenameListener } from '@ohos/libraryimageknife';
@Entry
@Component
struct CompressPage {
@State mRPixelMap?: PixelMap = undefined;
@State mFPixelMap?: PixelMap = undefined;
@State mResultText: string= "压缩回调结果"
@State mResultPath: string= "压缩路径:"
@State mAsyncPath: string= ""
@State mAsyncPathHint: string= ""
@State mResultText: string = "压缩回调结果"
@State mResultPath: string = "压缩路径:"
@State mAsyncPath: string = ""
@State mAsyncPathHint: string = ""
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) {
Column() {
Column() {
Text("Resource image compress").fontColor(Color.Gray).fontSize(16);
Text("Resource image compress")
.fontColor(Color.Gray)
.fontSize(16);
Button() {
Text("同步压缩").fontSize(13).fontColor(Color.White)
Text("同步压缩")
.fontSize(13)
.fontColor(Color.White)
}
.height(35)
.width(120)
.margin({ top: 10 })
.onClick(() => {
this.compressAsyncRecource();
this.compressAsyncResource();
});
Scroll(){
Text(this.mAsyncPathHint).fontSize(13)
Scroll() {
Text(this.mAsyncPathHint)
.fontSize(13)
}
.height(55)
.width(350)
@ -56,46 +58,64 @@ struct CompressPage {
.backgroundColor(Color.Pink)
Button() {
Text($r("app.string.resource_image_compress")).fontSize(13).fontColor(Color.White)
Text($r("app.string.resource_image_compress"))
.fontSize(13)
.fontColor(Color.White)
}
.height(35)
.width(120)
.margin({ top: 10 })
.onClick(() => {
this.cropressRecource();
this.compressResource();
});
Image(this.mRPixelMap == undefined?'': this.mRPixelMap!)
Image(this.mRPixelMap == undefined ? '' : this.mRPixelMap!)
.width(200)
.height(200)
.margin({ top: 10 })
Text(this.mResultText).fontColor(Color.Gray).fontSize(16);
Text(this.mResultPath).fontColor(Color.Gray).fontSize(16);
}.margin({ top: 10 });
Text(this.mResultText)
.fontColor(Color.Gray)
.fontSize(16);
Text(this.mResultPath)
.fontColor(Color.Gray)
.fontSize(16);
}
.margin({ top: 10 });
Column() {
Text("file image compress").fontColor(Color.Gray).fontSize(16);
Text("file image compress")
.fontColor(Color.Gray)
.fontSize(16);
Button() {
Text($r("app.string.file_image_compress")).fontSize(13).fontColor(Color.White)
Text($r("app.string.file_image_compress"))
.fontSize(13)
.fontColor(Color.White)
}
.height(35)
.width(120)
.margin({ top: 10 })
.onClick(() => {
});
Image(this.mFPixelMap == undefined ?'':this.mFPixelMap!)
Image(this.mFPixelMap == undefined ? '' : this.mFPixelMap!)
.width(200)
.height(200)
.margin({ top: 10 });
}.margin({ top: 10 }).visibility(Visibility.Hidden);
}.margin({ bottom: 30 });
}.width('100%').height('100%');
}
.margin({ top: 10 })
.visibility(Visibility.Hidden);
}
.margin({ bottom: 30 });
}
.width('100%')
.height('100%');
}
private compressAsyncRecource() {
private compressAsyncResource() {
let data = new Array<Resource>();
data.push($r('app.media.jpgSample'))
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
if(imageKnife!=undefined) {
let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance()
.getImageKnife()
if (imageKnife != undefined) {
imageKnife
.compressBuilder()
.load(data)
@ -108,7 +128,8 @@ struct CompressPage {
}
console.info("asasd start compress end")
}
private cropressRecource() {
private compressResource() {
let data = new Array<Resource>();
data.push($r('app.media.jpgSample'))
let rename: OnRenameListener = {
@ -118,12 +139,12 @@ struct CompressPage {
}
let listener: OnCompressListener = {
start:()=>{
start: () => {
this.mResultText = "start"
console.info("asasd start")
},
onSuccess:(p: PixelMap | null | undefined, path: string)=> {
if(p!=null && p!=undefined) {
onSuccess: (p: PixelMap | null | undefined, path: string) => {
if (p != null && p != undefined) {
let pack = p;
this.mRPixelMap = pack as PixelMap;
console.info("asasd success path:" + this.mRPixelMap)
@ -131,14 +152,15 @@ struct CompressPage {
this.mResultPath = path;
}
},
onError:(s: string)=>{
onError: (s: string) => {
console.info("asasd onError:" + s)
this.mResultText = "fail";
}
}
console.info("asasd start compress")
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife()
if(imageKnife != undefined) {
let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance()
.getImageKnife()
if (imageKnife != undefined) {
imageKnife
.compressBuilder()
.load(data)