中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

2017年網(wǎng)站設(shè)計(jì)磁力貓引擎

2017年網(wǎng)站設(shè)計(jì),磁力貓引擎,城鄉(xiāng)建設(shè)部網(wǎng)官方網(wǎng)站,移動(dòng)端網(wǎng)站制作模板背景 封裝一個(gè)選擇圖片和調(diào)用拍照相機(jī)的按鈕,展示api13下選擇圖片和調(diào)用相機(jī),可以使用不申請(qǐng)用戶權(quán)限的方式,進(jìn)行圖片的選擇和修改。但是,目前方案并未包含上傳圖片保存的功能,僅提供圖片選擇或者拍照后,圖…

背景


封裝一個(gè)選擇圖片和調(diào)用拍照相機(jī)的按鈕,展示api13下選擇圖片和調(diào)用相機(jī),可以使用不申請(qǐng)用戶權(quán)限的方式,進(jìn)行圖片的選擇和修改。但是,目前方案并未包含上傳圖片保存的功能,僅提供圖片選擇或者拍照后,圖片展示的一種方案。

在這里插入圖片描述

項(xiàng)目架構(gòu)

在這里插入圖片描述

  • Common :公共操作類存放文件夾
  • PromptActionClass:全局彈窗操作類
  • components:公共彈窗組件文件夾
  • SelectImageDialog:選擇圖片彈窗組件
  • pages->Index:入口界面

重要方法解析


調(diào)用相機(jī)拍照

  • 添加camera, cameraPicker的外部引用
import { camera, cameraPicker } from '@kit.CameraKit';
  • 使用cameraPicker的pick方法實(shí)現(xiàn)安全調(diào)用設(shè)備相機(jī),并返回選擇結(jié)果cameraPicker.PickerResult對(duì)象,通過(guò)設(shè)置cameraPicker.PickerProfile對(duì)象屬性實(shí)現(xiàn)對(duì)相機(jī)的初始化屬性設(shè)置。
try {//配置相機(jī)設(shè)置let pickerProfile: cameraPicker.PickerProfile = {cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK,};let result: cameraPicker.PickerResult =await cameraPicker.pick(getContext(), [cameraPicker.PickerMediaType.PHOTO],pickerProfile);if (result.resultCode == 0) {await this.UpdateShowImage(result.resultUri);}PromptActionClass.CloseDialog();return true;
} catch (e) {console.info(e);return false;
}

訪問(wèn)圖庫(kù)選擇圖片

  • 添加PromptActionClass的外部引用
import { PromptActionClass } from '../Common/PromptActionClass';
  • 使用photoAccessHelper.PhotoViewPicker對(duì)象的select方法,實(shí)現(xiàn)安全調(diào)用相冊(cè)并選擇圖片。通過(guò)photoAccessHelper.PhotoSelectOptions對(duì)象,對(duì)選擇方法進(jìn)行初始化,可以設(shè)置默認(rèn)選擇、選擇數(shù)量、選擇類型等。
try {const photoSelectOpt = new photoAccessHelper.PhotoSelectOptions();//設(shè)置選擇類型photoSelectOpt.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;//選擇圖片最大數(shù)量photoSelectOpt.maxSelectNumber = 1;//圖片選擇器const photoPicker = new photoAccessHelper.PhotoViewPicker();const selectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(photoSelectOpt)let uri: string = "";if (selectResult.isOriginalPhoto || selectResult.photoUris.length == 0) {return false;}uri = selectResult.photoUris[0];await this.UpdateShowImage(uri);PromptActionClass.CloseDialog();return true;
} catch (e) {console.info(e);return false;
}

整體代碼


Index

import { image } from '@kit.ImageKit';
import { photoAccessHelper } from '@kit.MediaLibraryKit';
import { fileIo } from '@kit.CoreFileKit';
import { PromptActionClass } from '../Common/PromptActionClass';
import { SelectImageDialog } from '../components/SelectImageDialog';
import { camera, cameraPicker } from '@kit.CameraKit';@Entry
@ComponentV2
struct Index {@Local ShowImage: ResourceStr | PixelMap = $r('app.media.AddImageIcon')aboutToAppear(): void {PromptActionClass.SetContext(this.getUIContext());PromptActionClass.SetOptions({builder: () => {this.PictureBuilder()},alignment: DialogAlignment.Bottom,cornerRadius: {topLeft: 20,topRight: 20,bottomLeft: 20,bottomRight: 20},height: 154,width: "90%",})}build() {RelativeContainer() {Button() {Image(this.ShowImage).width("100%").borderRadius(20).padding(10)}.width(120).height(120).type(ButtonType.Normal).backgroundColor(Color.White).borderWidth(3).borderColor('#592708').borderRadius(20).id("AddImageBtn").alignRules({middle: { anchor: "__container__", align: HorizontalAlign.Center }}).margin({ top: 20 }).onClick(() => {PromptActionClass.OpenDialog();})}.height('100%').width('100%')}@BuilderPictureBuilder() {SelectImageDialog({CancelEvent: async () => {try {PromptActionClass.CloseDialog();return true;} catch (e) {console.info(e);return false;}},TakePictureEvent: async () => {try {//配置相機(jī)設(shè)置let pickerProfile: cameraPicker.PickerProfile = {cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK,};let result: cameraPicker.PickerResult =await cameraPicker.pick(getContext(), [cameraPicker.PickerMediaType.PHOTO],pickerProfile);if (result.resultCode == 0) {await this.UpdateShowImage(result.resultUri);}PromptActionClass.CloseDialog();return true;} catch (e) {console.info(e);return false;}},SelectedPictureEvent: async () => {try {const photoSelectOpt = new photoAccessHelper.PhotoSelectOptions();//設(shè)置選擇類型photoSelectOpt.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;//選擇圖片最大數(shù)量photoSelectOpt.maxSelectNumber = 1;//圖片選擇器const photoPicker = new photoAccessHelper.PhotoViewPicker();const selectResult: photoAccessHelper.PhotoSelectResult = await photoPicker.select(photoSelectOpt)let uri: string = "";if (selectResult.isOriginalPhoto || selectResult.photoUris.length == 0) {return false;}uri = selectResult.photoUris[0];await this.UpdateShowImage(uri);PromptActionClass.CloseDialog();return true;} catch (e) {console.info(e);return false;}}})}async UpdateShowImage(uri: string) {let file = fileIo.openSync(uri, fileIo.OpenMode.READ_ONLY)const imageSourceApi = image.createImageSource(file.fd);let map: PixelMap = await imageSourceApi.createPixelMap();this.ShowImage = map;}
}

PromptActionClass

import { promptAction } from "@kit.ArkUI";
import { BusinessError } from "@kit.BasicServicesKit";/*** 彈窗操作類*/
export class PromptActionClass {/***展示界面的ID集合*/private static ShowIDArray: number[] = [];static Context: UIContext;/*** 彈窗界面設(shè)置*/static Options: promptAction.CustomDialogOptions;static SetContext(context: UIContext) {PromptActionClass.Context = context;}static SetOptions(options: promptAction.CustomDialogOptions) {PromptActionClass.Options = options;}/*** 彈窗*/static OpenDialog() {if (PromptActionClass.Options) {PromptActionClass.Context.getPromptAction().openCustomDialog(PromptActionClass.Options).then((id: number) => {PromptActionClass.ShowIDArray.push(id);console.info('彈窗已打開(kāi)')}).catch((error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`彈窗失敗,錯(cuò)誤代碼是:${code}, message 是 ${message}`);})}}/*** 關(guān)閉彈窗*/static CloseDialog() {if (PromptActionClass.ShowIDArray.length != 0) {try {PromptActionClass.Context.getPromptAction().closeCustomDialog(PromptActionClass.ShowIDArray[PromptActionClass.ShowIDArray.length-1])console.info('成功關(guān)閉彈窗.')} catch {(error: BusinessError) => {let message = (error as BusinessError).message;let code = (error as BusinessError).code;console.error(`彈窗關(guān)閉失敗,錯(cuò)誤代碼:${code}, message 是 ${message}`);}}}}
}

SelectImageDialog

@ComponentV2
export struct SelectImageDialog {@Event TakePictureEvent: () => Promise<boolean> = async () => {return false;}@Event SelectedPictureEvent: () => Promise<boolean> = async () => {return false;}@Event CancelEvent: () => Promise<boolean> = async () => {return false;}build() {RelativeContainer() {Button("拍照").type(ButtonType.Normal).width("100%").id("TakePictureBtn").backgroundColor("#ffffff").height(50).fontColor("#343434").alignRules({bottom: { anchor: "SelectedPictureBtn", align: VerticalAlign.Top }}).onClick(async () => {await this.TakePictureEvent();})Button("從相冊(cè)中選擇").type(ButtonType.Normal).width("100%").height(50).id("SelectedPictureBtn").backgroundColor("#ffffff").fontColor("#343434").borderWidth({ bottom: 2, top: 2 }).borderColor("#f6f6f6").alignRules({center: { anchor: "__container__", align: VerticalAlign.Center }}).onClick(async () => {await this.SelectedPictureEvent();})Button("取消").width("100%").type(ButtonType.Normal).height(50).backgroundColor("#ffffff").fontColor("#aeaeae").alignRules({top: { anchor: "SelectedPictureBtn", align: VerticalAlign.Bottom }}).onClick(async () => {await this.CancelEvent();})}.height("100%").width("100%")}
}

圖片資源

從綁定資源中下載

代碼文件下載

ImageSelectDemo: 圖片選擇博客代碼

http://www.risenshineclean.com/news/1782.html

相關(guān)文章:

  • 上海專業(yè)做網(wǎng)站公司電話注冊(cè)域名費(fèi)用一般多少錢
  • 手機(jī)怎么制作釣魚(yú)網(wǎng)站網(wǎng)絡(luò)營(yíng)銷組織的概念
  • 大公司做網(wǎng)站seo分析
  • 用什么做視頻網(wǎng)站比較好個(gè)人在百度上發(fā)廣告怎么發(fā)
  • 大型門戶網(wǎng)站建設(shè)包括哪些方面seoapp推廣
  • 上海網(wǎng)站建設(shè)推薦今日新聞?lì)^條最新消息
  • 注冊(cè)了域名怎么做網(wǎng)站成全在線觀看免費(fèi)高清動(dòng)漫
  • 做炫舞情侶頭像動(dòng)態(tài)圖網(wǎng)站推廣是什么意思
  • 國(guó)外做節(jié)目包裝的網(wǎng)站網(wǎng)上做推廣怎么收費(fèi)
  • 2015年做啥網(wǎng)站能致富廣告推廣一個(gè)月多少錢
  • 青海高端網(wǎng)站建設(shè)價(jià)格長(zhǎng)沙網(wǎng)紅打卡景點(diǎn)排行榜
  • 網(wǎng)站備案查詢 whois百度網(wǎng)站提交
  • 網(wǎng)站開(kāi)發(fā)預(yù)算報(bào)表企點(diǎn)官網(wǎng)
  • 查排名的軟件有哪些關(guān)于華大18年專注seo服務(wù)網(wǎng)站制作應(yīng)用開(kāi)發(fā)
  • wap網(wǎng)站制作開(kāi)發(fā)公司成品人和精品人的區(qū)別在哪
  • 政府網(wǎng)站的欄目建設(shè)小程序免費(fèi)制作平臺(tái)
  • 網(wǎng)站建設(shè)費(fèi)做什么會(huì)計(jì)科目百度收錄怎么弄
  • 阿里云網(wǎng)站黃桃圖片友情鏈接
  • 上傳網(wǎng)站安裝教程上海搜索引擎推廣公司
  • wordpress中聯(lián)系表網(wǎng)站如何優(yōu)化流程
  • 青島網(wǎng)站建設(shè)多少錢seo是什么意思中文
  • 網(wǎng)站做代理服務(wù)器市場(chǎng)營(yíng)銷考試題目及答案2022
  • asp動(dòng)態(tài)網(wǎng)站建設(shè)答辯上海seo優(yōu)化培訓(xùn)機(jī)構(gòu)
  • 境外建網(wǎng)站網(wǎng)絡(luò)推廣平臺(tái)有哪些?
  • 武漢武漢最新優(yōu)化seo教程
  • 域名做網(wǎng)站出售合法嗎最強(qiáng)大的搜索引擎
  • 國(guó)外做化工產(chǎn)品的網(wǎng)站好的在線crm系統(tǒng)
  • 學(xué)校的二級(jí)網(wǎng)站怎么建設(shè)百度網(wǎng)頁(yè)
  • 深圳網(wǎng)站制作品牌祥奔科技數(shù)字營(yíng)銷包括哪六種方式
  • 馬蜂窩網(wǎng)站做的重點(diǎn)怎么設(shè)置自己的網(wǎng)站