This commit is contained in:
yumoqing 2024-11-19 18:14:43 +08:00
parent 16c96b762d
commit 2436404f2f
4 changed files with 21 additions and 2 deletions

View File

@ -47,7 +47,6 @@ bricks.Image = class extends bricks.JsWidget {
// 获取画布数据并转换为 base64
var dataURL = canvas.toDataURL('image/png'); // 可以根据需要修改图像格式
dataURL = this.removeBase64Header(dataURL);
console.log(dataURL);
return dataURL;
}
set_url(url){

BIN
bricks/imgs/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
bricks/imgs/camera.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -344,6 +344,11 @@ bricks.UiImage =class extends bricks.VBox {
opts.name = opts.name || 'image';
super(opts);
this.uitype='image';
this.camera_w = new bricks.Icon({
url:bricks_resource('imgs/camera.png'),
rate:1.5});
this.add_widget(this.camera_w);
this.camera_w.bind('click', this.take_photo.bind(this));
this.bind('drop', this.dropHandle.bind(this));
this.input = document.createElement('input');
this.input.type = 'file';
@ -354,6 +359,19 @@ bricks.UiImage =class extends bricks.VBox {
this.dom_element.appendChild(this.input);
this.imgw = null;
}
take_photo(){
var camera = new bricks.Camera({});
camera.bind('shot', function(d){
if (this.imgw){
this.remove_widget(this.imgw);
}
this.imgw = new bricks.Image({
url:d,
width:'100%'
});
this.add_widget(this.imgw);
});
}
handleFileSelect(event){
const file = event.target.files[0];
this.show_image(file);
@ -367,7 +385,9 @@ bricks.UiImage =class extends bricks.VBox {
show_image(file) {
const reader = new FileReader();
reader.onload = (e) => {
this.clear_widgets();
if (this.imgw){
this.remove_widget(this.imgw);
}
this.imgw = new bricks.Image({
url:e.target.result,
width:'100%'