|
- <?xml version="1.0" encoding="utf-8"?>
- <div xmlns="http://www.w3.org/1999/xhtml" component="$UI/system/components/justep/window/window" design="device:m;"
- xid="window" class="window">
- <div component="$UI/system/components/justep/model/model" xid="model" style="left:18px;top:83px;height:244px;"
- onLoad="modelLoad"/>
- <div component="$UI/system/components/justep/panel/panel" class="x-panel x-full"
- xid="panel1">
- <div class="x-panel-top" xid="top1">
- <div component="$UI/system/components/justep/titleBar/titleBar" title="图片添加水印"
- class="x-titlebar">
- <div class="x-titlebar-left">
- <a component="$UI/system/components/justep/button/button" label=""
- class="btn btn-link btn-only-icon" icon="icon-chevron-left" onClick="{operation:'window.close'}"
- xid="backBtn">
- <i class="icon-chevron-left"/>
- <span/>
- </a>
- </div>
- <div class="x-titlebar-title">图片添加水印</div>
- <div class="x-titlebar-right reverse"/>
- </div>
- </div>
- <div class="x-panel-content" xid="content1">
- <div xid="div1">
- <canvas id="myCanvas"/>
- </div>
- </div>
- </div>
- </div>
复制代码- define(function(require) {
- var $ = require("jquery");
- var justep = require("$UI/system/lib/justep");
- var Model = function() {
- this.callParent();
- };
- Model.prototype.modelLoad = function(event) {
- var self = this;
- var img = new Image();
- img.src = require.toUrl('picture.jpg');// 图片路径
- // 加载完成开始绘制
- img.onload = function() {
- // 准备canvas环境
- var canvas = document.getElementById("myCanvas");
- canvas.width = 383;
- canvas.height = 579;
- var ctx = canvas.getContext('2d');
- // 绘制图片
- ctx.drawImage(img, 0, 0, 383, 579);
- // 绘制水印
- ctx.font = "20px Georgia";
- ctx.fillStyle = "rgba(255,255,255,1)";
- ctx.fillText("Hello World!", 10, 50);
- ctx.font = "30px Verdana";
- // 创建渐变
- var gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
- gradient.addColorStop("0", "magenta");
- gradient.addColorStop("0.5", "blue");
- gradient.addColorStop("1.0", "red");
- // 用渐变填色
- ctx.fillStyle = gradient;
- ctx.fillText("2016/06/28", 10, 90);
- };
- };
- return Model;
- });
复制代码 利用canvas给图片添加水印,很简单的一种实现方式。
|
|