提交 d8f2be1c 编写于 作者: AndroidLeaves's avatar AndroidLeaves

update

上级 e4b7aab6
......@@ -47,7 +47,78 @@ class Widget extends BaseWidget {
}
async render({ widgetSetting, family }) {
return await this.provideWidget(family, this.photoHalving());
let widget = new ListWidget();
widget.setPadding(0, 0, 0, 0);
let image = await this.drawSFIcon2();
let imgSpan = widget.addImage(image);
// let textSpan = widget.addText('HTML5 Canvas Shadow')
// textSpan.font = Font.systemFont(30)
// textSpan.textColor = Color.white()
console.log(`>>>>>>>>>${image.size.width}, ${image.size.height}`);
// Photos.save(image)
// let scale = Device.screenScale();
// imgSpan.imageSize = new Size(image.size.width / scale, image.size.height / scale);
return widget;
}
drawSFIcon2 = async (
) => {
try {
const { width, height } = this.getWidgetSize('中号')
console.log(`---------${width}`);
const html = `
<img id="silhouetteImg" src="" />
<canvas id="mainCanvas" width="${width}" height="${height}" />
`
const js = `
var canvas = document.getElementById("mainCanvas");
var context = canvas.getContext("2d");
context.textBaseline= "hanging";
let width = canvas.width, height = canvas.height;
if (window.devicePixelRatio) {
canvas.style.width = width + "px";
canvas.style.height = height + "px";
canvas.height = height * window.devicePixelRatio;
canvas.width = width * window.devicePixelRatio;
context.scale(window.devicePixelRatio, window.devicePixelRatio);
}
// context.shadowOffsetX = 10;
// context.shadowOffsetY = 10;
// context.shadowBlur = 4;
// context.shadowColor = "#666666";//或使用rgb(红色,绿色,蓝色)
context.fillStyle = "#FFFFFF";
context.font = "normal 30px Arial";
context.textBaseline= "hanging";
context.fillText("HTML5 Canvas Shadow", 0, 20);
var imgData = context.getImageData(0, 0, canvas.width, canvas.height);
context.putImageData(imgData, 0, 0);
silhouetteImg.src = canvas.toDataURL();
output = canvas.toDataURL()
`
let wv = new WebView();
await wv.loadHTML(html);
const base64Image = await wv.evaluateJavaScript(js);
const iconImage = await new Request(base64Image).loadImage();
return iconImage;
} catch (error) {
console.error(error);
this.ERRS.push(error);
if (!config.runsInApp) {
await this.notify('icon绘制', `🚫 ${error}`);
} else {
throw error
}
}
}
// --------------------------NET START--------------------------
......
......@@ -3,7 +3,7 @@
// icon-color: red; icon-glyph: user-astronaut;
/**
* Author:LSP
* Date:2022-12-08
* Date:2022-12-09
*/
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
......@@ -392,7 +392,7 @@ class Widget extends BaseWidget {
});
}
return infoArr;
return infoArr.length > 1 ? infoArr.slice(0, 2) : infoArr;
}
// --------------------------NET END--------------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册