demo报错修改

This commit is contained in:
tsm 2024-04-29 21:23:22 +08:00
parent e137e2c836
commit 5d9a3f521b
1 changed files with 18 additions and 28 deletions

View File

@ -12,41 +12,31 @@
* 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 { RequestOption, ImageKnifeGlobal, ImageKnifeOption, ImageKnifeComponent } from '@ohos/libraryimageknife' import { ImageKnifeComponent, ImageKnifeOption } from '@ohos/libraryimageknife'
import { BusinessError } from '@ohos.base' import { BusinessError } from '@ohos.base'
import { ImageKnifeData } from '@ohos/libraryimageknife'
import {
DownsampleNone,
FitCenter
} from '@ohos/imageknife/src/main/ets/components/inageknife/Downsampling/Downsamplestartegy'
// PixelMap transform示例
let mRotate: number = 0; let mRotate: number = 0;
//let mUrl= "https://hbimg.huabanimg.com/cc6af25f8d782d3cf3122bef4e61571378271145735e9-vEVqqB" let murl = $r('app.media.pngSample'); let setting = new DownsampleNone()
let mUrl = $r('app.media.pngSample'); let mUrl = $r('app.media.pngSample');
let setting = new DownsampleNone()
@Entry @Entry
@Component @Component
struct DownsamplingPage { struct DownsamplingPage {
@State url: string = ""; @State url: string = "";
@State mCropPixelMap?: PixelMap = undefined; @State mCropPixelMap?: PixelMap = undefined;
@state mRoundPixelMap?: PixelMap = undefined; @State mRoundPixelMap?: PixelMap = undefined;
@State mCirclePixelMap?: PixelMap = undefined; @State mCirclePixelMap?: PixelMap = undefined;
@State mCircleBorderPixelMap?: PixelMap = undefined; @State mCircleBorderPixelMap?: PixelMap = undefined;
@state mRotatePixelMap?: PixelMap = undefined; @State mRotatePixelMap?: PixelMap = undefined;
@state mSquarePixelMap?: PixelMap = undefined; @State mSquarePixelMap?: PixelMap = undefined;
@state mSquarePixelMap1?: PixelMap = undefined; @State mSquarePixelMap1?: PixelMap = undefined;
@state mClipCenterPixelMap?: PixelMap = undefined; @State mClipCenterPixelMap?: PixelMap = undefined;
@state mClipBottomPixelMap?: PixelMap = undefined; @State mClipBottomPixelMap?: PixelMap = undefined;
@state mGrayscalePixelMap?: PixelMap = undefined; @State mGrayscalePixelMap?: PixelMap = undefined;
@state mBrightnessPixelMap?: PixelMap = undefined; @State mBrightnessPixelMap?: PixelMap = undefined;
@State mContrastPixelMap?: PixelMap = undefined; @State mContrastPixelMap?: PixelMap = undefined;
@state mInvertPixelMap?: PixelMap = undefined; @State mInvertPixelMap?: PixelMap = undefined;
@state mSepiaPixelMap?: PixelMap = undefined; @State mSepiaPixelMap?: PixelMap = undefined;
@State mSketchPixelMap?: PixelMap = undefined; @State mSketchPixelMap?: PixelMap = undefined;
@state mBlurPixelMap?: PixelMap = undefined; @State mBlurPixelMap?: PixelMap = undefined;
@state mPixelPixelMap?: PixelMap = undefined; @State mPixelPixelMap?: PixelMap = undefined;
@State mSwirlPixelMap?: PixelMap = undefined; @State mSwirlPixelMap?: PixelMap = undefined;
@State mMaskPixelMap?: PixelMap = undefined; @State mMaskPixelMap?: PixelMap = undefined;
@State mKuwaharaPixelMap?: PixelMap = undefined; @State mKuwaharaPixelMap?: PixelMap = undefined;
@ -54,7 +44,7 @@ struct DownsamplingPage {
@State mVignettePixelMap?: PixelMap = undefined; @State mVignettePixelMap?: PixelMap = undefined;
@State BytesNumber: number = 0; @State BytesNumber: number = 0;
@State BytesNumber1: number = 0; @State BytesNumber1: number = 0;
@state imageKnifeOption2: ImageKnifeOption = @State imageKnifeOption2: ImageKnifeOption =
{ {
loadSrc: $r('app.media.gifSample'), loadSrc: $r('app.media.gifSample'),
placeholderSrc: $r('app.media.icon_loading'), placeholderSrc: $r('app.media.icon_loading'),
@ -74,7 +64,7 @@ struct DownsamplingPage {
.height(35) .height(35)
.width(120) .width(120)
.margin({ top: 10 }) .margin({ top: 10 })
.onclick(() => { .onClick(() => {
this.transformSquare(); this.transformSquare();
}); });
if (this.mSquarePixelMap) { if (this.mSquarePixelMap) {
@ -90,7 +80,7 @@ struct DownsamplingPage {
Column() { Column() {
Text("大小:" + this.BytesNumber1).fontColor(Color.Gray).fontSize(16); Text("大小:" + this.BytesNumber1).fontColor(Color.Gray).fontSize(16);
Button() { Button() {
Text('降采样').fontsize(13).fontColor(Color.White) Text('降采样').fontSize(13).fontColor(Color.White)
} }
.height(35).width(120) .height(35).width(120)
.margin({ top: 10 }) .margin({ top: 10 })
@ -107,7 +97,7 @@ struct DownsamplingPage {
}.margin({ top: 10 }); }.margin({ top: 10 });
}.margin({ bottom: 30 }); }.margin({ bottom: 30 });
Column() { Column() {
column() { Column() {
Text("ImageKnifeComponent用法").fontColor(Color.Gray).fontSize(16); Text("ImageKnifeComponent用法").fontColor(Color.Gray).fontSize(16);
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 }) ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption2 })
.width(200) .width(200)
@ -121,7 +111,7 @@ struct DownsamplingPage {
//正方形裁剪 //正方形裁剪
transformSquare() { transformSquare() {
let imageKnifeOption = new RequestOption(); let imageKnifeOption = new RequestOption();
imageKnifeOption.load(murl) imageKnifeOption.load(mUrl)
.addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => { .addListener({ callback: (err: BusinessError | string, data: ImageKnifeData) => {
this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap; this.mSquarePixelMap = data.drawPixelMap?.imagePixelMap as PixelMap;
this.BytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber() this.BytesNumber = (data.drawPixelMap?.imagePixelMap as PixelMap).getPixelBytesNumber()