鸿蒙 自定义绘制各种图形(示例代码) 原创
陈浩南xxx
发布于 2021-4-30 11:33
浏览
4收藏
方便需要用到时,直接拷贝
1,绘制横线
2,绘制圆
3,画矩形
4,画弧度
5,画图片
6,绘制渐变的弧形
(示例源代码不在了,就贴出了大概思路) 效果图是旋转过的,代码没有旋转
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
标签
已于2022-5-5 15:26:17修改
赞
5
收藏 4
回复
5
2
4
相关推荐
public class PixelMapUtil {
private static HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x000001, "PixelMapUtil");
/**
* 根据图片资源id获取PixelMap
*
* @param context context
* @param resourceId resourceId
* @return 图片的PixelMap
*/
public static Optional<PixelMap> getPixelMapFromResource(Context context, int resourceId) {
InputStream inputStream = null;
ImageSource imageSource = null;
ImageSource.DecodingOptions decodingOptions = null;
try {
// 创建图像数据源ImageSource对象
inputStream = context.getResourceManager().getResource(resourceId);
ImageSource.SourceOptions srcOpts = new ImageSource.SourceOptions();
srcOpts.formatHint = "image/jpg";
imageSource = ImageSource.create(inputStream, srcOpts);
// 设置图片参数
decodingOptions = new ImageSource.DecodingOptions();
} catch (IOException e) {
HiLog.info(label, "IOException");
} catch (NotExistException e) {
HiLog.info(label, "NotExistException");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
HiLog.info(label, "inputStream IOException");
}
}
}
if (imageSource != null && decodingOptions != null) {
return Optional.ofNullable(imageSource.createPixelmap(decodingOptions));
}
return Optional.empty();
}
}
持续更新的精神必须学习