精华内容
下载资源
问答
  • 园艺插画海报模板

    2021-08-01 07:13:39
    园艺插画海报模板适用于园艺海报设计
  • 冬日悠闲插画海报设计适用于Hygee海报设计
  • 瑜伽卡通插画海报设计适用于瑜伽活动海报设计
  • 冬天舒适悠闲PSD插画海报适用于Hygee插画海报设计
  • 妇女节插画海报设计矢量适用于妇女节插画海报设计的AI格式素材。
  • 瑜伽冥想PSD人物插画海报适用于运动海报设计
  • 享受假日PSD手绘插画海报适用于假日海报设计
  • 2021牛年新春插画海报

    2021-07-20 04:34:06
    2021牛年新春插画海报适用于春节商场海报设计
  • 阅读主题插画海报设计PSD适用于阅读主题海报设计
  • 女神节卡通插画海报设计适用于女神节海报设计。
  • 38女王节插画海报设计适用于女王节海报设计。
  • 设计师工作插画海报设计适用于设计师招聘海报设计
  • 秋日水彩插画海报模板适用于秋季海报设计的AI格式素材
  • 音乐节矢量插画海报

    2021-07-26 18:36:44
    音乐节矢量插画海报适用于音乐节海报设计的AI格式素材
  • 女权插画海报设计PSD素材适用于女权海报设计
  • 我们毕业啦插画海报设计适用于毕业季海报设计
  • 佩戴口罩宣传画海报设计素材适用于佩戴口罩宣传海报设计。
  • 3.12植树节宣传画海报设计适用于312植树节海报设计。
  • 父亲节宣传画海报设计矢量适用于父亲节海报设计的AI格式素材。
  • 妇女节宣传画海报设计矢量适用于妇女节海报设计的AI格式素材。
  • 客厅装饰美化挂画海报样机素材下载 产品样机、客厅挂画海报模板、客厅装饰样机、画框样机、高端样机
  • canvas画海报

    2020-10-11 12:40:50
    实现了canvas画海报并修复多图片异步加载,绘制完成回调 由vue的vue-canvas-poster改造及完善通用js版 使用示例 var tct = new TB_CanvasTools({ //包裹图片的jq对象 "pcontent":$("#hb"), //背景颜色 ...

    实现了canvas画海报并修复多图片异步加载,绘制完成回调

    由vue的vue-canvas-poster改造及完善通用js版

    2020-10-12 //修復儅父元素未设置宽高的页面卡死的情况

    使用示例

    var tct = new TB_CanvasTools({
                	
                	//包裹图片的jq对象
                	"pcontent":$("#hb"),
                	//背景颜色
                	"backgroundColor":"#fff",
                	//渲染完成回调事件
                	"callback":function(params){
                		
                		var imageBase64 = params.imageBase64;console.log(imageBase64);
                		$("#hbImage").attr("src",imageBase64);
                	}
                	
                });
                
                //要画的元素集
                var views = [{
                	//类型 image/text
                    type: 'image',
                    //如果是图片的话,图片地址
                    url: '${ctxStatic}/newcontract4.0/images/dianxin_logo_icon.png',
                    //css,这里的值都是比例
                    css: {
                        top: 0.05,
                        left: 0.05,
                        width: 0.3
                    },
                    list: [{
                        type: 'image',
                        url: '${ctxStatic}/newcontract4.0/images/haibao.png',
                        css: {
                            top: 0.15,
                            left: 0.05,
                            width: 0.9
                        }
                    },
                    {
                         type: 'text',
                         text: `今天你消费 我买单!`,
                         css: {
                             color: '#FF9601',
                             fontSize: 20,
                             top: 0.8,
                             left: 0.05
                         }
                     }]
                }]
                
                tct.drawCanvas({
                	
                	"views":views
                	
                });

     

    工具代码

    var TB_CanvasTools = function(params){
    	
    	var $this = this;
    	
    	if(!params){
    		params = {};
    	}
    	
    	//包裹图片的元素jq对象
    	var pcontent = params.pcontent;
    	var backgroundColor = params.backgroundColor;
        var callback = params.callback;
    	
    	$this.pcontent = pcontent;
    	$this.backgroundColor = backgroundColor;
    	$this.callback = callback;
    	
    	//canvas 的宽和高
    	$this.width = $this.pcontent.width();
    	$this.height = $this.pcontent.height();
        //修復儅父元素为设置宽高的情况
        if($this.width == 0 && $this.height == 0){
    		
    		$this.width = 400;
    		$this.height = 400;
    		
    	}
    	
    	$this.width = ($this.width == 0?$this.height:$this.width);
    	$this.height = ($this.height == 0?$this.width:$this.height);
    	
    	//要绘制的内容数
    	$this.viewsSize = 0;
    	
    	//创建canvas对象
    	var canvas=document.createElement("canvas");
    	canvas.width=$this.width;
    	canvas.height=$this.height;
    	
    	var ctx = canvas.getContext("2d");
    	$this.ctx = ctx;
    	$this.canvas = canvas;
    	
    	$this.ctx.rect(0, 0, $this.width, $this.height);
        $this.ctx.fillStyle = $this.backgroundColor;
        $this.ctx.fill();
    	
        //进行绘制的方法
        $this.drawCanvas = function(params){
        	
          $this.views = params.views;	
          
          if(!params){
        	  params = {}
          }
        
          $this.viewsSize = 0;
          
          $this.views.forEach(cur => {
        	initViewSize(cur);
          })
          
          $this.views.forEach(cur => {
            drawView(cur)
          })
        }
        
        //绘制图片
        var _drawImage = function(view){
        	
    		 if(!view.url){
    		   return ;
    		 }
    		 let {
    		   top,left,width,height
    		 } = view.css;
    		 
    		 var image = view.image;
    		 var iw = image.width;
    		 var ih = image.height;
    		 //计算宽高
    		 width = getWidth(width);
    		 //height = getHeight(height);
    		 height = width/iw*ih;
    		 top = getHeight(top);
    		 left = getWidth(left);
    		 
    		 if (typeof view.url === 'string') {
    		   $this.ctx.fillStyle = '#ddd'
    		   $this.ctx.fillRect(left, top, width, height);
    		   $this.ctx.restore()
    		   return
    		 }
    		 $this.ctx.save();
    		 
    		 $this.ctx.drawImage(view.url, left, top, width, height);
    		 $this.ctx.restore();
    		 
    		 //绘制记录数减一
    		 $this.viewsSize--;
    		 if($this.viewsSize == 0){
    			 //如果记录数减为0则回调
    		 	  finish();
    		 }
    		 
    		 //绘制子
    		 if (view.list && view.list.length > 0) {
    		   view.list.forEach(cur => drawView(cur))
    		 }
        }
        
        /**
         * 绘制文字 
         **/
        var _drawText = function(view, ctx) {
        	
          let css = {
            color: '#333333',
            lineHeight: 30,
            textAlign: 'start',
            maxLines: 3,
            fontSize: 20,
            top: 0,
            left: 0,
            width: 1,
            textBaseline: 'alphabetic'
          }
          
          css = { ...css, ...view.css };
    
          //设置宽
          css.width = getWidth(css.width);
    	  css.top = getHeight(css.top);
    	  css.left = getWidth(css.left);
          
          $this.ctx.save();
          $this.ctx.textAlign  = css.textAlign;
          $this.ctx.textBaseline = css.textBaseline;
          $this.ctx.fillStyle = css.color;
          $this.ctx.font = css.fontSize + 'px  Arial';
          let result = breakLinesForCanvas(view.text, css.width, ctx);
          for (let i = 0; i < result.length; i++) {
        	  
            if (i <= css.maxLines - 1) {
              let str = result[i];
              if ((i === css.maxLines - 1) && ($this.ctx.measureText(str+"...").width > css.width)) {
                result[i] = str.substring(0, str.length - 1)+"...";
              }
            } else {
              break;
            }
            $this.ctx.fillText(result[i], css.left, css.top + i * css.lineHeight, css.width);
          }
          $this.ctx.restore();
    
          $this.viewsSize--;
          if($this.viewsSize == 0){
        	  finish();
          }
          if(view.list && view.list.length > 0){
            view.list.forEach(cur => drawView(cur))
          }
        };
        
    	/**
    	 * 
    	 * ==================================function====================================
    	 * 
    	 */
    	/**
    	 * 获取内容的宽
    	 * 
    	 * @params widthScale 宽的比例
    	 */
    	var getWidth = function(widthScale){
    		
    		return widthScale*$this.width;
    		
    	}
    	
    	/**
    	 * 获取内容的高
    	 * 
    	 * @params heightScale 高的比例
    	 */
    	var getHeight = function(heightScale){
    		
    		return heightScale*$this.height;
    		
    	}
    	
    	/**
         * 打断文本,返回给canvas绘制
         * */
        var breakLinesForCanvas = function(text, width, ctx) {
        	
          let result = [];
          let breakPoint = 0;
          while ((breakPoint = findBreakPoint(text, width, ctx)) !== -1) {
            result.push(text.substr(0, breakPoint));
            text = text.substr(breakPoint);
          }
    
          if (text) {
            result.push(text);
          }
          return result;
        }
        
        /**
         * 获取文本换行断点
         * */
        var findBreakPoint = function(text, width, ctx) {
          var min = 0;
          var max = text.length - 1;
          while (min <= max) {
            var middle = Math.floor((min + max) / 2);
            var middleWidth = $this.ctx.measureText(text.substr(0, middle)).width;
            var oneCharWiderThanMiddleWidth = $this.ctx.measureText(text.substr(0, middle + 1)).width;
            if (middleWidth <= width && oneCharWiderThanMiddleWidth > width) {
              return middle;
            }
            if (middleWidth < width) {
              min = middle + 1;
            } else {
              max = middle - 1;
            }
          }
          return -1;
        }
        
        /**
         * 绘制
         */
        var drawView = function(cur){
        	
        	var $this = this;
        	
          switch (cur.type) {
            case 'image':
              if (cur.url) {
                downloadImage(cur.url).then(image => {
                  cur.url = image;
                  cur.image = image;
                  _drawImage(cur);
                });
              }
              break;
            case 'text':
            	_drawText(cur, this.ctx)
              break;
            default:
              break;
          }
        }
        
       /**
        * 绘制完成后
        */
        var finish = function(){
        	
        	var imageBase64 = $this.canvas.toDataURL('image/png')
        	//回调
        	if($this.callback){
        		$this.callback({
        			
        			"imageBase64":imageBase64
        			
        		});
        	}
        }
        
        /**
         * 
         * 初始化内容元素数量
         * 
         */
        var initViewSize = function(view){
    
            $this.viewsSize++;
        	
        	if(view.list){
    
        		view.list.forEach(cur => initViewSize(cur))
        		
        	}
        }
        
        var downloadImage = function(src){
            return new Promise((resolve, reject) => {
              if (src.startsWith('#')) {
                resolve(src)
                return
              }
              const img = new Image()
              img.onload = () => resolve(img)
              img.onerror = () => reject(`下载图片失败`+src)
              img.crossOrigin = 'anonymous'
              img.src = src
              if (img.complete === true) {
                setTimeout(() => resolve(img), 500)
              }
            })
          }
    }
    

     

    展开全文
  • 收藏级别的抽象艺术涂鸦插画海报 抽象艺术、收藏级艺术插画、艺术涂鸦
  • 3d插画海报宣传游戏工作室类网站html模板
  • RAVI社交媒体动画海报组合.psd素材下载 —没有标签
  • 主要介绍了小程序使用canvas自适应屏幕画海报并保存图片功能,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
  • 微信小程序用canvas画海报生成照片保存相册 效果展示 代码实现 1.wxml <button bindtap='formSubmit'>生成海报</button> <view class='imagePathBox' hidden="{{maskHidden == false}}"> <...

    微信小程序用canvas画海报生成照片保存相册

    效果展示

    在这里插入图片描述

    代码实现

    1.wxml

    <button bindtap='formSubmit'>生成海报</button>
       <view class='imagePathBox' hidden="{{maskHidden == false}}">
          <image src="{{imagePath}}" class='create'></image>
          <view class="poster-button">
           <button class='keep' bindtap='keep'>保存相册,分享到朋友圈</button>
          </view>
        </view>
       <view hidden="{{maskHidden == false}}" class="mask"></view> 
      <view class="canvas-box">
          <canvas  style="width: 375px;height: 667px;position:fixed;top:9999px" canvas-id="mycanvas"/>
      </view>  
    

    2.wxss

    
    .imagePathBox{
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99;
    }
    .create{
    width: 80%;
    height: 80%;
    position: fixed;
    top: 50rpx;
    left: 50%;
    margin-left: -40%;
    z-index: 10;
    }
    .poster-button{
    position: fixed;
    bottom:50rpx;
    width: 100%;
    height:80rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    }
    .keep{
    width: 80%;
    border-radius: 98rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    height: 80rpx;
    background: #6899FF;
    color: #ffffff;
    font-size: 25rpx;
    }
    button[class="keep"]::after{
    border: 0;
    }
    

    3.js

    const app = getApp()
    Page({
      data: {
        maskHidden: false,
      },
     
      //将canvas转换为图片保存到本地
      createNewImg: function () {
        var that = this;
        var context = wx.createCanvasContext('mycanvas');
        context.setFillStyle("#6899FF")
        context.fillRect(0, 0, 375, 667)
        var path = "/image/3.png";
        context.drawImage(path, 10, 10, 355, 647);
      
        context.setFontSize(24);
        context.setFillStyle('#E0A859');
        context.setTextAlign('center');
        context.fillText("楼/盘/推/荐", 180, 50);
        context.stroke();
    
        context.setFontSize(14);
        context.setFillStyle('#949494');
        context.setTextAlign('center');
        context.fillText("—— 向您推荐一个好楼盘 ——", 180, 80);
        context.stroke();
    
       var path1 = "/image/27.jpg";
        context.drawImage(path1, 20, 100, 335, 217);
        var path2 = "/image/1.jpg";
        context.drawImage(path2, 146, 520, 80, 80);
     
    
        context.setFontSize(20);
        context.setFillStyle('#5A5472');
        context.setTextAlign('left');
        context.fillText("风清云都", 30, 347);
        context.stroke();
    
        context.setFontSize(20);
        context.setFillStyle('#FD7B48');
        context.setTextAlign('right');
        context.fillText("1200m^2", 335, 347);
        context.stroke();
    
        context.setFontSize(16);
        context.setFillStyle('#AAACBA');
        context.setTextAlign('left');
        context.fillText("地址:嘉兴市南湖区越秀北路洪兴交界处", 30, 377);
        context.stroke();
    
        context.setFontSize(16);
        context.setFillStyle('#AAACBA');
        context.setTextAlign('left');
        context.fillText("面积:29-50m^2", 30, 407);
        context.stroke();
    
        context.setFontSize(20);
        context.setFillStyle('#FD7B48');
        context.setTextAlign('left');
        context.fillText("地理位置好,环境优美,物超所值!", 30, 457);
        context.stroke();
        context.draw();
      
        //将生成好的图片保存到本地
        setTimeout(function () {
          wx.canvasToTempFilePath({
            canvasId: 'mycanvas',
            success: function (res) {
              var tempFilePath = res.tempFilePath;
              that.setData({
                imagePath: tempFilePath,
                canvasHidden: true
              });
            },
            fail: function (res) {
              console.log(res);
            }
          });
        }, 200);
      },
      //点击生成
      formSubmit: function (e) {
        var that = this;
        this.setData({
          maskHidden: false
        });
        wx.showToast({
          title: '生成中',
          icon: 'loading',
          duration: 1000
        });
        setTimeout(function () {
          wx.hideToast()
          that.createNewImg();
          that.setData({
            maskHidden: true
          });
        }, 1000)
      },
      //点击保存到相册
      keep: function () {
        var that = this
        wx.saveImageToPhotosAlbum({
          filePath: that.data.imagePath,
          success(res) {
            wx.showModal({
              content: '图片已保存到相册,赶紧晒一下吧~',
              showCancel: false,
              confirmText: '好的',
              confirmColor: '#333',
              success: function (res) {
                if (res.confirm) {
                  console.log('成功');
                  /* 该隐藏的隐藏 */
                  that.setData({
                    maskHidden: false
                  })
                }
              }, fail: function (res) {
                console.log("失败")
              }
            })
          }
        })
      }
      
    })
    
    展开全文
  • <!DOCTYPE html> <html lang="en"> <head> ...meta charset="utf-8">...原生js canvas 画海报</title> <meta name="viewport" content="width=device-width, initial-scale=1....
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>原生js canvas 画海报</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" />
    <script src="js/axios.min.js"></script>
    <script src="js/vconsole.min.js"></script>
    <script src="js/jquery.js"></script>
    <script type="text/javascript">
        var vConsole = new VConsole();
        document.documentElement.style.fontSize=document.documentElement.clientWidth/7.5+"px";window.onresize=function(){document.documentElement.style.fontSize=document.documentElement.clientWidth/7.5+"px";};
    </script>
    <style type="text/css">
    
    *{margin: 0;padding: 0;}
    
    body{
        font-size: .3rem;
    }
    
    .createBtn{
        height: .8rem;
        line-height: .8rem;
        margin-bottom: .3rem;
        text-align: center;
        background: #f5f5f5;
    }
    .showPoster{
        display: block;
        width: 80%;
        margin: 0 auto;
        border: 1px solid lime;
    }
    
    </style>
    </head>
    <body>
    
    <p class="createBtn" onclick="Poster()">生成</p>
    <img class="showPoster" id="posterBox">
    
    <script type="text/javascript">
    // 注意 测试时如果使用本地图片,要使用服务器打开,不然可能会碰到跨域问题
    
    let posterBox = document.getElementById("posterBox");
    
    // 生成海报 原生绘制
    function Poster(){
        // here open loading  // loading 开启
        console.log("原生js canvas 开始画海报 satrt");
        let that = this;
        let c = document.createElement('canvas');
        let width = 750;
        let height = 1205;
        c.width = width;
        c.height = height;
        const ctx = c.getContext("2d");
    
        // 填充背景色
        ctx.fillStyle = "#ffffff";
        ctx.fillRect(0, 0, 750, 1205);
    
        // 画 大背景
        let bg = new Image();
        bg.src = './test/poster_bg.png';  // 背景图片地址
        // bg.setAttribute("crossOrigin", "anonymous");
        bg.onload = ()=>{
            ctx.drawImage(bg, 0, 0, c.width, 969);
    
            // 画 头像
            let head = new Image();
            // head.setAttribute("crossOrigin", "anonymous");   // 设置网络图片跨域的问题, 如果图片有跨域要设置,需要关注一下是在设置src前或者是之后设置,之前碰到这点有问题,忘了
            head.src = './test/logo.png';  // logo图片地址
            // head.setAttribute("crossOrigin", "anonymous");
            head.onload = ()=>{
                ctx.save();
                let qrX = 30;
                let qrY = 1001;
                let qrW = 80;
                // ctx.beginPath();
                ctx.arc(qrX + qrW / 2, qrY + qrW / 2, qrW / 2, 0, Math.PI * 2, false);
                // ctx.strokeStyle = "lime";
                // ctx.lineWidth = 1;
                // ctx.stroke();
                // ctx.closePath();
                ctx.clip();
                ctx.drawImage(head, 30, 1001, 80, 80);
                ctx.restore();
            }
    
            // 画 昵称
            ctx.font = "24px PingFangSC";
            ctx.fillStyle = "#4a4a4a";
            ctx.fillText("Haleays", 127, 1030);  // nickName
    
            // 画 文案1
            ctx.font = "28px PingFangSC";
            ctx.fillText('一起来学画海报', 127, 1075);
    
            // 画 文案2
            ctx.font = "28px PingFangSC";
            ctx.fillText('你学会了吗哈哈', 525, 1114);
    
            // 画 文案3
            ctx.font = "28px PingFangSC";
            ctx.fillText('要多学习', 568, 1154);
    
            // 画 QRcode
            let QRcode = new Image();
            QRcode.src = './test/sun_qr_01.jpg'; // QRcode 地址
            // QRcode.setAttribute("crossOrigin",'Anonymous')
            QRcode.onload = ()=>{
                ctx.save();
                let qrX = 550;
                let qrY = 924;
                let qrW = 142;
                ctx.beginPath();
                ctx.arc(qrX + qrW / 2, qrY + qrW / 2, qrW / 2, 0, Math.PI * 2, false);
                ctx.strokeStyle = "#D8D8D8";
                ctx.lineWidth = 1;
                ctx.stroke();
                ctx.closePath();
                ctx.clip();
                ctx.drawImage(QRcode, 550, 924, 142, 142);
                ctx.restore();
            }
        }
        setTimeout(()=>{  // 延迟1s设置img地址,因为可能直接设置,canvas还没有画完,就会空白
            // here close Loading // loading 关闭
            posterBox.src = c.toDataURL();
            // document.body.appendChild(c);  // 把canvas插入到document中
        }, 1000);
        console.log("原生js canvas 开始画海报 end");
    
    }
    
    </script>
    </body>
    </html>
    
    
    展开全文
  • vue canvas画海报

    2020-11-05 14:51:01
    -- 设置了两个块区域 当点击了生成海报时把canvas转换成base64的图片,然后把最开始当样式隐藏掉 把获取的的base64的地址赋值给src--> <img v-if="!test" :src="imgSrc" alt /> <div v-else> //src

    安装:

    npm install html2canvas --save
    npm i qrcanvas --save

    html:

           <div>
          <!-- 设置了两个块区域 当点击了生成海报时把canvas转换成base64的图片,然后把最开始当样式隐藏掉 把获取的的base64的地址赋值给src-->
        <img v-if="!test" :src="imgSrc"   alt />
        <div v-else>
    //src图片可以替换成自己想要的图片
          <img src="~@/images/invitation/theme_icon.png" alt />
          <div id="qrcode"></div>
          <div id="invitation">测试数据啊,使用id,只生成这个内容啊</div>  
          <button @click="btn">点我生成</button>
     <button @click="btn">保存到本地</button>
        </div>
      </div>

    js:

    <script>
    //生成一个二维码
    import { qrcanvas } from "qrcanvas";
    //将整个页面转换成canvas
    import html2canvas from "html2canvas";
    
        export default {
      data() {
        return {
          test: true,
          imgSrc: ""
        };
      },
      methods: {
    //生成邀请函
        btn() {
              //生成一个二维码 data是二维码跳转的地址(写自己需要跳转的地址即可)
         // const canvas = qrcanvas({
            //data: location.href   
          //});
          //document.getElementById("qrcode").appendChild(canvas);
    //此上部分去掉则不会生成二维码
            //点击生成canvas转换成base64的图片
          this.$nextTick(() => {
            const that = this;
    //document.body生成整个页面的内容document.getElementById('invitation')生成某个id为invitation的内容
            html2canvas(document.getElementById('invitation')).then(function(canvas) {
              console.log(canvas.toDataURL());
              that.imgSrc = canvas.toDataURL();
            });
            //隐藏元素
            this.test = false;
          });
        },
      //保存邀请函到本地
        // 下载邀请函
        generatorImage() {
            let link = document.createElement("a");
            link.href = this.imgSrc;//下载链接
            link.setAttribute("download","邀请函.png");
            link.style.display = "none";//a标签隐藏
            document.body.appendChild(link);
            link.click();
        },
      }
    };
    </script>
    

    参考网址:

    https://blog.csdn.net/weixin_45389051/article/details/105493364

    https://www.cnblogs.com/shcs/p/11960593.html

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 11,057
精华内容 4,422
关键字:

如何画海报