网站asp怎么没有菜单栏有了域名 怎么做网站
网站asp怎么没有菜单栏,有了域名 怎么做网站,戴尔网站建设成功,免费发短信的在线网站关于
提供了一个轻量级的图像压缩库。将允许您将大照片压缩成小 尺寸的照片#xff0c;图像质量损失或可以忽略不计
compress 的依赖添加
为你的应用添加 compress-debug.har。将 compress-debug.har 复制到 entry\libs 目录下即可#xff08;由于 build.gradle 中已经依赖…关于
提供了一个轻量级的图像压缩库。将允许您将大照片压缩成小 尺寸的照片图像质量损失或可以忽略不计
compress 的依赖添加
为你的应用添加 compress-debug.har。将 compress-debug.har 复制到 entry\libs 目录下即可由于 build.gradle 中已经依赖的 libs 目录下的*.har因此不需要在做修改。 使用
1ability_main.xml 设置界面布局
DependentLayout
xmlns:ohoshttp://schemas.huawei.com/res/ohos
ohos:widthmatch_parent
ohos:heightmatch_parent
ohos:background_element#FFFFFF
Image
ohos:id$id:image1
ohos:heightmatch_parent
ohos:widthmatch_parent
ohos:image_src$media:dog1.PNG/
Text
ohos:id$id:textohos:widthmatch_content
ohos:heightmatch_content
ohos:text
ohos:text_size19fp
ohos:text_color#1C1C1C
ohos:top_padding8vp
ohos:bottom_padding8vp
ohos:right_padding70vp
ohos:left_padding70vp
ohos:center_in_parenttrue
ohos:align_parent_bottomtrue
ohos:bottom_margin120vp/
Button
ohos:id$id:choose_button
ohos:widthmatch_content
ohos:heightmatch_content
ohos:textChoose Image
ohos:text_size19fp
ohos:text_color#FFFFFF
ohos:top_padding8vp
ohos:bottom_padding8vp
ohos:right_padding70vp
ohos:left_padding70vp
ohos:background_element$graphic:background_button
ohos:center_in_parenttrue
ohos:align_parent_bottomtrue
ohos:bottom_margin75vp/
Button
ohos:id$id:button
ohos:widthmatch_content
ohos:heightmatch_content
ohos:textCompress
ohos:text_size19fp
ohos:text_color#FFFFFF
ohos:top_padding8vp
ohos:bottom_padding8vp
ohos:right_padding70vp
ohos:left_padding70vp
ohos:background_element$graphic:background_button
ohos:center_in_parenttrue
ohos:align_parent_bottomtrue
ohos:bottom_margin15vp/
/DependentLayout2MainAbilitySlice
获取界面的按钮并分别向按钮绑定点击事件
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
// 请求文件的读取权限
String[] permissions {ohos.permission.READ_USER_STORAGE};
requestPermissionsFromUser(permissions, 0);
// 获取压缩按钮并绑定事件
Button button (Button) findComponentById(ResourceTable.Id_button);
if (button ! null) {
// 为按钮设置点击回调
button.setClickedListener(new Component.ClickedListener() {
Override
public void onClick(Component component) {
try {
File file new File(System.getProperty(java.io.tmpdir) File.separator tmpName);
HiLog.error(LOG_LABEL, old size... file.length() ...b);
// 默认压缩
// File newFile Compressor.defaultCompress(file);
// 自定义压缩
File newFile Compressor.customCompress(getContext(), file, 500, 1000, 60);
Text text (Text) findComponentById(ResourceTable.Id_text);
text.setText(size: newFile.length() b);
HiLog.error(LOG_LABEL, new size... newFile.length() ...b);
PixelMap newPixelMap Compressor.decode(newFile);
Image image (Image) findComponentById(ResourceTable.Id_image1);
image.setPixelMap(newPixelMap);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
// 获取选择图片按钮并绑定事件
Button chooseButton (Button) findComponentById(ResourceTable.Id_choose_button);
if (chooseButton ! null) {
// 为按钮设置点击回调
chooseButton.setClickedListener(new Component.ClickedListener() {
Override
public void onClick(Component component) {
DataAbilityHelper helper DataAbilityHelper.creator(getContext());
try {
ResultSet resultSet helper.query(AVStorage.Images.Media.EXTERNAL_DATA_ABILITY_URI,
null, null);
while (resultSet ! null resultSet.goToNextRow()) {
// 互殴媒体库的图片
int id
resultSet.getInt(resultSet.getColumnIndexForName(AVStorage.Images.Media.ID));
HiLog.error(LOG_LABEL, id:... id ...);
Uri uri
Uri.appendEncodedPathToUri(AVStorage.Images.Media.EXTERNAL_DATA_ABILITY_URI, id);
// 根据图片的 uri 打开文件并保存到临时目录中
FileDescriptor fileDescriptor helper.openFile(uri, r);
ImageSource.DecodingOptions decodingOpts new ImageSource.DecodingOptions();
decodingOpts.sampleSize ImageSource.DecodingOptions.DEFAULT_SAMPLE_SIZE;
ImageSource imageSource ImageSource.create(fileDescriptor, null);
PixelMap pixelMap imageSource.createThumbnailPixelmap(decodingOpts, true);
ImagePacker imagePacker ImagePacker.create();
tmpName UUID.randomUUID().toString();
File file new File(System.getProperty(java.io.tmpdir) File.separator
tmpName);
FileOutputStream outputStream new FileOutputStream(file);
ImagePacker.PackingOptions packingOptions new ImagePacker.PackingOptions();
packingOptions.quality 100;
boolean result imagePacker.initializePacking(outputStream, packingOptions);
result imagePacker.addImage(pixelMap);
long dataSize imagePacker.finalizePacking();
// 显示图片和图片大小
Text text (Text) findComponentById(ResourceTable.Id_text);
text.setText(size: file.length() b);
Image image (Image) findComponentById(ResourceTable.Id_image1);
image.setPixelMap(pixelMap);
}
} catch (DataAbilityRemoteException | FileNotFoundException e) {
e.printStackTrace();
}
}
});
}
}3结果展示 4Compressor 核心方法
defaultCompress(Context context, File file)输入用户需要处理的文件
输出处理后的临时文件
处理流程传入图片后先将图片拷贝到临时目录再按照默认的压缩处理方法完成后返回处理后图片的临时目录
customCompress(Context context, File file, int width, int height, int quality)输入用户需要处理的文件处理后的宽度、高度以及图片质量。
输出处理后的临时文件
处理流程传入图片后先将图片拷贝到临时目录再按照指定的处理方法进行
压缩完成后返回处理后图片的临时目录
decode(File file)输入图片的目录
输出图片的像素矩阵形式
作用用于界面图片展示
为了能让大家更好的学习鸿蒙HarmonyOS NEXT开发技术这边特意整理了《鸿蒙开发学习手册》共计890页希望对大家有所帮助https://qr21.cn/FV7h05
《鸿蒙开发学习手册》
如何快速入门https://qr21.cn/FV7h05
基本概念构建第一个ArkTS应用…… 开发基础知识https://qr21.cn/FV7h05
应用基础知识配置文件应用数据管理应用安全管理应用隐私保护三方应用调用管控机制资源分类与访问学习ArkTS语言…… 基于ArkTS 开发https://qr21.cn/FV7h05
Ability开发UI开发公共事件与通知窗口管理媒体安全网络与链接电话服务数据管理后台任务(Background Task)管理设备管理设备使用信息统计DFX国际化开发折叠屏系列…… 鸿蒙开发面试真题含参考答案https://qr18.cn/F781PH 鸿蒙开发面试大盘集篇共计319页https://qr18.cn/F781PH
1.项目开发必备面试题 2.性能优化方向 3.架构方向 4.鸿蒙开发系统底层方向 5.鸿蒙音视频开发方向 6.鸿蒙车载开发方向 7.鸿蒙南向开发方向
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/91574.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!