当前位置: 首页 > wzjs >正文

做非法网站怎样量刑北京网站优化平台

做非法网站怎样量刑,北京网站优化平台,惠州seo网站推广,中国城乡建设结合部网站*本文共四个功能函数,相当于四个插件。作者为了偷懒写成了一个插件,调对应的函数即可。 1、chooseImageHarmony函数:拉起相册选择图片并转为Base64 2、takePhotoAndConvertToBase64函数:拉起相机拍照并转为Base64 3、openBrows…

*本文共四个功能函数,相当于四个插件。作者为了偷懒写成了一个插件,调对应的函数即可。

1、chooseImageHarmony函数:拉起相册选择图片并转为Base64
2、takePhotoAndConvertToBase64函数:拉起相机拍照并转为Base64
3、openBrowser函数:打开外部的华为浏览器并跳转
4、openAppMarket函数:打开鸿蒙应用商店并跳转

以下为实现的核心代码

index.uts
import picker from '@ohos.file.picker';
import fs from '@ohos.file.fs';
import image from '@ohos.multimedia.image';
import { ImageUtil } from '@pura/harmony-utils';import picker2 from '@ohos.multimedia.cameraPicker'
import camera from '@ohos.multimedia.camera';
import common from '@ohos.app.ability.common';
// import { BusinessError } from '@ohos.base';
import fileuri from '@ohos.file.fileuri';
// import fs from '@ohos.file.fs';
import { buffer } from '@kit.ArkTS';
import { image as image2 } from '@kit.ImageKit';import { Want, common as common2 } from '@kit.AbilityKit';// 拉起相册选择图片并转为Base64
export async function chooseImageHarmony(): Promise<string> {let file: fs.File | null = null;let imageSource: image.ImageSource | null = null;let pixelMap: image.PixelMap | null = null;try {// 1. 调用文件选择器const photoPicker = new picker.PhotoViewPicker();const selectOptions: picker.PhotoSelectOptions = {maxSelectNumber: 1, // 限制只能选择 1 张图片MIMEType: picker.PhotoViewMIMETypes.IMAGE_TYPE, // 可选:限制图片类型};const fileResult = await photoPicker.select(selectOptions);// 2. 获取到URIconst uri = fileResult.photoUris[0];// 3. 使用文件描述符file = fs.openSync(uri, fs.OpenMode.READ_ONLY);// 4. 创建ImageSource并获取PixelMapimageSource = image.createImageSource(file.fd);// 5. 获取图片属性来得到原始尺寸const imageInfo = await imageSource.getImageInfo();const originalWidth = imageInfo.size.width;const originalHeight = imageInfo.size.height;// 6. 定义压缩选项 - 使用正确的类型声明const decodingOptions: image.DecodingOptions = {desiredSize: {width: Math.min(800, originalWidth),  // 不超过800pxheight: Math.round((Math.min(800, originalWidth) / originalWidth) * originalHeight)},desiredPixelFormat: image.PixelMapFormat.RGBA_8888,// 以下是必须包含的默认值desiredRegion: {size: { width: originalWidth, height: originalHeight },x: 0,y: 0},editable: false};pixelMap = await imageSource.createPixelMap(decodingOptions);// 7. 转换为Base64const base64Str: string = await ImageUtil.pixelMapToBase64Str(pixelMap);return base64Str} catch (error) {return ""} finally {imageSource?.release()pixelMap?.release();// 关闭文件(使用 fs.close(file.fd))if (file?.fd !== undefined) {fs.close(file.fd); // ✅ HarmonyOS NEXT 使用 fs.close(fd)}}
}class CameraPosition {cameraPosition: camera.CameraPosition;saveUri: string;constructor(cameraPosition: camera.CameraPosition, saveUri: string) {this.cameraPosition = cameraPosition;this.saveUri = saveUri;}
}// 拉起相机拍照并转为Base64
export async function takePhotoAndConvertToBase64(): Promise<string> {let base64Str = ''// 获取上下文const context = getContext() as common.Context;const pathDir = context.filesDir;// 文件临时路径const filePath = pathDir + '/' + new Date().getTime() + '.jpg';fs.createRandomAccessFileSync(filePath, fs.OpenMode.CREATE);const uri = fileuri.getUriFromPath(filePath);try {// 唤起相机let pickerProfile = new CameraPosition(camera.CameraPosition.CAMERA_POSITION_BACK, uri);await picker2.pick(context, [picker2.PickerMediaType.PHOTO], pickerProfile);const file = await fs.open(uri, fs.OpenMode.READ_ONLY);const imageSource: image.ImageSource = image2.createImageSource(file.fd);const imagePackerApi = image2.createImagePacker();const packOpts: image.PackingOption = { format: "image/jpeg", quality: 70 };const imageBuffer = await imagePackerApi.packing(imageSource, packOpts);base64Str = buffer.from(imageBuffer).toString('base64');const base64Str2 = 'data:image/jpeg;base64,' + base64Str;return base64Str2;} catch (error) {// let err = error as BusinessError;console.error(`拍照失败`);return '';} finally {}
}// 打开外部的华为浏览器并跳转
export function openBrowser(url: string): void {// 1. 获取正确的上下文const context = getContext() as common2.UIAbilityContext;// 2. 明确定义 Want 类型const want: Want = {"action": "ohos.want.action.viewData","entities": ["entity.system.browsable"],"uri": url,"type": "text/plain"};// 3. 正确处理 Promise 类型context.startAbility(want).then((): void => {  // 明确指定返回类型console.log('openUrl: successfully');}).catch((err: Error): void => {  // 明确指定返回类型和错误类型console.error('openURL Failed:', err);});
}// 打开鸿蒙应用商店并跳转
export function openAppMarket(url: string): void {// 1. 获取正确的上下文const context = getContext() as common2.UIAbilityContext;const appMarketWant: Want = {uri: url,};context.startAbility(appMarketWant).then((): void => {console.log('AppMarket opened successfully');}).catch((err: Error): void => {console.error('Failed to open AppMarket:', err);});
}

使用示例:

导入插件:
import { chooseImageHarmony, takePhotoAndConvertToBase64, openBrowser, openAppMarket } from “@/uni_modules/ywx-getImageToBase64”;

调用函数:
1、const base64Data = await chooseImageHarmony();
2、const base64Data = await takePhotoAndConvertToBase64();
3、openBrowser(“https://hmapp.gisgm.cn/tdjg”)
4、openAppMarket(“store://appgallery.huawei.com/app/detail?id=” + ‘com.example.shilrey’)

作者已经实现的功能,有任何疑问请在评论区讨论。

http://www.dtcms.com/wzjs/288175.html

相关文章:

  • 怎么介绍自己的网站建设数据分析师培训
  • 网站建设 财务归类天津网站快速排名提升
  • 网站页面的宽度seo网站推广什么意思
  • 做网站全包百度营销搜索推广
  • 国内全屏网站有哪些互联网营销师培训多少钱
  • 贵州专业建网站网站手机优化
  • 企业网站建设合同 百度文库优秀网站设计网站
  • 福田做商城网站建设多少钱app运营方案
  • 汕头金平区疫情最新消息站长之家seo一点询
  • 西安疫情最新动态成都网站快速优化排名
  • 网站建设与管理维护百度识图网页版在线
  • 贵州省建设执业资格促进会网站中国十大热门网站排名
  • 政府网站建设团队湖南网站建设加盟代理
  • 黑龙江网站建设巨耀网络天津短视频seo
  • 常州营销型网站建设贵州网站seo
  • 大连做环评网站免费发布信息平台有哪些
  • 腾讯文件怎么转换wordpress短视频seo代理
  • 建设第三方公众号平台网站教程域名解析ip地址查询
  • 襄阳哪里有做网站的西安seo排名收费
  • 修改wordpress的权限设置seo搜索引擎推广
  • 提高asp.net网站安全性沈阳网站seo
  • 基于jquery做的网站百度竞价广告代理
  • jsp网站 iis国内做网站比较好的公司
  • 广东如何做网络推广营销策划方案win优化大师怎么样
  • 吴忠网站建设衡阳seo
  • 江西建设职业技术学院迎新网站西安seo培训机构
  • 沈阳新民网站建设在线seo推广软件
  • 淄博哪有培训做网站的网站查询seo
  • 个人电脑做网站saascrm国内免费pdf
  • 证书兼职网优优群排名优化软件