diff --git a/bricks/image.js b/bricks/image.js index 58d4b7a..977a340 100755 --- a/bricks/image.js +++ b/bricks/image.js @@ -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){ diff --git a/bricks/imgs/app.png b/bricks/imgs/app.png new file mode 100644 index 0000000..d89daba Binary files /dev/null and b/bricks/imgs/app.png differ diff --git a/bricks/imgs/camera.png b/bricks/imgs/camera.png new file mode 100644 index 0000000..cc86861 Binary files /dev/null and b/bricks/imgs/camera.png differ diff --git a/bricks/input.js b/bricks/input.js index a7a0680..1e039cc 100755 --- a/bricks/input.js +++ b/bricks/input.js @@ -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%'