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,10 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {ImageKnife} from '@ohos/libraryimageknife' import { ImageKnife, ImageKnifeGlobal, OnCompressListener, OnRenameListener } from '@ohos/libraryimageknife';
import {OnRenameListener} from '@ohos/libraryimageknife'
import {OnCompressListener} from '@ohos/libraryimageknife'
import {ImageKnifeGlobal} from '@ohos/libraryimageknife'
@Entry @Entry
@Component @Component
@ -32,18 +29,23 @@ struct CompressPage {
Column() { Column() {
Column() { Column() {
Text("Resource image compress").fontColor(Color.Gray).fontSize(16); Text("Resource image compress")
.fontColor(Color.Gray)
.fontSize(16);
Button() { Button() {
Text("同步压缩").fontSize(13).fontColor(Color.White) Text("同步压缩")
.fontSize(13)
.fontColor(Color.White)
} }
.height(35) .height(35)
.width(120) .width(120)
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
this.compressAsyncRecource(); this.compressAsyncResource();
}); });
Scroll() { Scroll() {
Text(this.mAsyncPathHint).fontSize(13) Text(this.mAsyncPathHint)
.fontSize(13)
} }
.height(55) .height(55)
.width(350) .width(350)
@ -56,26 +58,37 @@ struct CompressPage {
.backgroundColor(Color.Pink) .backgroundColor(Color.Pink)
Button() { 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) .height(35)
.width(120) .width(120)
.margin({ top: 10 }) .margin({ top: 10 })
.onClick(() => { .onClick(() => {
this.cropressRecource(); this.compressResource();
}); });
Image(this.mRPixelMap == undefined ? '' : this.mRPixelMap!) Image(this.mRPixelMap == undefined ? '' : this.mRPixelMap!)
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }) .margin({ top: 10 })
Text(this.mResultText).fontColor(Color.Gray).fontSize(16); Text(this.mResultText)
Text(this.mResultPath).fontColor(Color.Gray).fontSize(16); .fontColor(Color.Gray)
}.margin({ top: 10 }); .fontSize(16);
Text(this.mResultPath)
.fontColor(Color.Gray)
.fontSize(16);
}
.margin({ top: 10 });
Column() { Column() {
Text("file image compress").fontColor(Color.Gray).fontSize(16); Text("file image compress")
.fontColor(Color.Gray)
.fontSize(16);
Button() { 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) .height(35)
.width(120) .width(120)
@ -86,15 +99,22 @@ struct CompressPage {
.width(200) .width(200)
.height(200) .height(200)
.margin({ top: 10 }); .margin({ top: 10 });
}.margin({ top: 10 }).visibility(Visibility.Hidden);
}.margin({ bottom: 30 });
}.width('100%').height('100%');
} }
private compressAsyncRecource() { .margin({ top: 10 })
.visibility(Visibility.Hidden);
}
.margin({ bottom: 30 });
}
.width('100%')
.height('100%');
}
private compressAsyncResource() {
let data = new Array<Resource>(); let data = new Array<Resource>();
data.push($r('app.media.jpgSample')) data.push($r('app.media.jpgSample'))
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance()
.getImageKnife()
if (imageKnife != undefined) { if (imageKnife != undefined) {
imageKnife imageKnife
.compressBuilder() .compressBuilder()
@ -108,7 +128,8 @@ struct CompressPage {
} }
console.info("asasd start compress end") console.info("asasd start compress end")
} }
private cropressRecource() {
private compressResource() {
let data = new Array<Resource>(); let data = new Array<Resource>();
data.push($r('app.media.jpgSample')) data.push($r('app.media.jpgSample'))
let rename: OnRenameListener = { let rename: OnRenameListener = {
@ -137,7 +158,8 @@ struct CompressPage {
} }
} }
console.info("asasd start compress") console.info("asasd start compress")
let imageKnife:ImageKnife|undefined = ImageKnifeGlobal.getInstance().getImageKnife() let imageKnife: ImageKnife | undefined = ImageKnifeGlobal.getInstance()
.getImageKnife()
if (imageKnife != undefined) { if (imageKnife != undefined) {
imageKnife imageKnife
.compressBuilder() .compressBuilder()