




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、蛟龍騰飛學(xué)習(xí)分享材料HarmonyOS應(yīng)用開發(fā)-Doodle圖像編輯主鍵體驗(yàn)演示視頻:效果圖如下所示: 該組件有畫筆縮放,旋轉(zhuǎn)等功能,可以自定義布局,掉用其接口完成圖片編輯的功能。部分代碼:public class MainAbility extends Ability private static final int PERMISSION_REQUEST_INTERACTIVE = 1; private static final int REQ_CODE_SELECT_IMAGE = 100; private static final int REQ_CODE_DOODLE = 101; p
2、rivate final static int mDuration = 20000; private Text mPath; private Image mSaveImg; private DataAbilityHelper mHelper; private boolean mIsOpenImageSelector = false; private final static String mPermmReadMedia = ohos.permission.READ_MEDIA; Override public void onStart(Intent intent) super.onStart(
3、intent); setUIContent(ResourceTable.Layout_ability_main); requestPermissionsFromUser(new StringSystemPermission.READ_USER_STORAGE, SystemPermission.WRITE_USER_STORAGE, SystemPermission.READ_MEDIA, SystemPermission.WRITE_MEDIA, SystemPermission.MEDIA_LOCATION, PERMISSION_REQUEST_INTERACTIVE); mSaveIm
4、g = (Image) findComponentById(ResourceTable.Id_img); findComponentById(ResourceTable.Id_btn_select_image).setClickedListener(new Component.ClickedListener() Override public void onClick(Component component) checkPermission(); ); findComponentById(ResourceTable.Id_btn_guide).setClickedListener(new Co
5、mponent.ClickedListener() Override public void onClick(Component component) Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId().withBundleName(getBundleName() .withAbilityName(com.example.doodledemo.guide.DoodleGuideAbility).build(); intent.setOperation(
6、operation); startAbility(intent); ); findComponentById(ResourceTable.Id_btn_mosaic).setClickedListener(new Component.ClickedListener() Override public void onClick(Component component) Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId().withBundleName(ge
7、tBundleName() .withAbilityName(com.example.doodledemo.MosaicDemo).build(); intent.setOperation(operation); startAbility(intent); ); findComponentById(ResourceTable.Id_btn_scale_gesture).setClickedListener(new Component.ClickedListener() Override public void onClick(Component component) Intent intent
8、 = new Intent(); Operation operation = new Intent.OperationBuilder() .withDeviceId().withBundleName(getBundleName() .withAbilityName(com.example.doodledemo.ScaleGestureItemDemoAbility) .build(); intent.setOperation(operation); startAbility(intent); ); mPath = (Text) findComponentById(ResourceTable.I
9、d_img_path); private void checkPermission() if (verifySelfPermission(mPermmReadMedia) != IBundleManager.PERMISSION_GRANTED) / 應(yīng)用未被授予權(quán)限 if (canRequestPermission(mPermmReadMedia) / 是否可以申請彈框授權(quán)(首次申請或者用戶未選擇禁止且不再提示) requestPermissionsFromUser( new StringmPermmReadMedia, PERMISSION_REQUEST_INTERACTIVE); el
10、se if (!mIsOpenImageSelector) Intent intent = new Intent(); intent.setParam(ImageSelectorActivity.KEY_IS_MULTIPLE_CHOICE, false); intent.setParam(ImageSelectorActivity.KEY_MAX_COUNT, Integer.MAX_VALUE); Operation operation = new Intent.OperationBuilder() .withDeviceId() .withBundleName(getBundleName
11、() .withAbilityName(com.example.doodle.imagepicker.ImageSelectorActivity) .build(); intent.setOperation(operation); mIsOpenImageSelector = !mIsOpenImageSelector; startAbilityForResult(intent, REQ_CODE_SELECT_IMAGE); Override public void onRequestPermissionsFromUserResult(int requestCode, String perm
12、issions, int grantResults) super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults); if (requestCode = PERMISSION_REQUEST_INTERACTIVE) if (!(grantResults.length 0 & grantResults0 = IBundleManager.PERMISSION_GRANTED) Toast.showLong(this, 請前往“設(shè)置”授予“存儲訪問權(quán)限”); Override protected
13、void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) super.onOrientationChanged(displayOrientation); Override protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) super.onAbilityResult(requestCode, resultCode, resultData); if (requestCode = REQ_C
14、ODE_SELECT_IMAGE) mIsOpenImageSelector = false; if (resultData = null) return; if (resultCode = ImageSelectorActivity.RESULT_OK) Intent intent = new Intent(); Uri uri = resultData.getUri(); intent.setUriAndType(uri, null); Operation operation = new Intent.OperationBuilder() .withDeviceId() .withBund
15、leName(getBundleName() .withAbilityName(com.example.doodle.DoodleAbility) .build(); intent.setOperation(operation); startAbilityForResult(intent, REQ_CODE_DOODLE); else if (requestCode = REQ_CODE_DOODLE) if (resultData = null) return; if (resultCode = DoodleAbility.RESULT_OK) Uri uri = resultData.ge
16、tUri(); String path = resultData.getStringParam(DoodleAbility.KEY_IMAGE_PATH); if (TextTool.isNullOrEmpty(path) return; showSavePic(uri); mPath.setText(path); LogUtil.d(onAbilityResult, path= + path); else if (resultCode = DoodleAbility.RESULT_ERROR) ToastDialog toastDialog = new ToastDialog(this);
17、toastDialog.setText(error).setAlignment(1).setDuration(mDuration).show(); private void showSavePic(Uri uri) if (mHelper = null) mHelper = DataAbilityHelper.creator(getContext(); FileDescriptor filedesc = null; try filedesc = mHelper.openFile(uri, r); catch (DataAbilityRemoteException | FileNotFoundException e) e.getMessage(); ImageSource.DecodingOptions decodingOpts = new ImageSource.DecodingOptions(); decodingOpts.desiredSize = new Size(Util.getScreenWidth(this), Util.getScreenHeight(this); ImageSource imageSource = ImageSource.create(filedesc, null); PixelMap pixel
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 智能照明在餐廳包間照明中的應(yīng)用考核試卷
- 文化差異與跨文化的安全管理考核試卷
- 拍賣行合作模式創(chuàng)新考核試卷
- 跨部門協(xié)作下的保安工作流程計(jì)劃
- 電商平臺下農(nóng)產(chǎn)品物流的特色與挑戰(zhàn)
- 科技電商平臺運(yùn)營模式及盈利途徑的多元化發(fā)展
- 裝飾石材施工合同范本
- 儀器儀表制造業(yè)的全球市場營銷與品牌推廣考核試卷
- 人造板企業(yè)市場營銷組合策略與實(shí)施考核試卷
- 收購黑皮冬瓜合同范本
- 化工原理-第三章-過濾課件
- 2023年通遼市中考數(shù)學(xué)試卷及答案
- 腸內(nèi)營養(yǎng)考評標(biāo)準(zhǔn)終
- Mysql 8.0 OCP 1Z0-908 CN-total認(rèn)證備考題庫(含答案)
- 三年級下冊音樂教學(xué)計(jì)劃含教學(xué)進(jìn)度安排活動設(shè)計(jì)word表格版
- STEM教學(xué)設(shè)計(jì)與實(shí)施PPT完整全套教學(xué)課件
- 門窗加工制作合同
- 項(xiàng)目邊坡護(hù)坡工程施工組織設(shè)計(jì)
- 四年級上冊音樂《楊柳青》課件PPT
- 安徽省廬陽區(qū)小升初語文試卷含答案
- 全國2017年4月自考00043經(jīng)濟(jì)法概論(財(cái)經(jīng)類)試題及答案
評論
0/150
提交評論