怎么用java给头像添加一个国旗图案-创新互联
这篇文章主要介绍“怎么用java给头像添加一个国旗图案”,在日常操作中,相信很多人在怎么用java给头像添加一个国旗图案问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用java给头像添加一个国旗图案”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及成都纸箱等,在网站建设公司、营销型网站建设、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。代码如下
var cvs = document.getElementById("cvs");var ctx = cvs.getContext("2d");var exportImage = document.getElementById("export");var img = document.getElementById("img");var hat = "hat6";var canvasFabric;var hatInstance;var screenWidth = window.screen.width < 500 ? window.screen.width : 300;function viewer() { var file = document.getElementById("upload").files[0]; console.log(file); var reader = new FileReader; if (file) { reader.readAsDataURL(file); reader.onload = function(e) { img.src = reader.result; img.onload = function() { img2Cvs(img) } } } else { img.src = "" }}function img2Cvs(img) { cvs.width = img.width; cvs.height = img.height; cvs.style.display = "block"; canvasFabric = new fabric.Canvas("cvs", { width: screenWidth, height: screenWidth, backgroundImage: new fabric.Image(img, { scaleX: screenWidth / img.width, scaleY: screenWidth / img.height }) }); changeHat(); document.getElementById("uploadContainer").style.display = "none"; document.getElementById("uploadText").style.display = "none"; document.getElementById("upload").style.display = "none"; document.getElementById("change").style.display = "block"; document.getElementById("exportBtn").style.display = "block"; document.getElementById("tip").style.opacity = 1}function changeHat() { document.getElementById(hat).style.display = "none"; var hats = document.getElementsByClassName("hide"); hat = "hat" + (+hat.replace("hat", "") + 1) % hats.length; var hatImage = document.getElementById(hat); hatImage.style.display = "block"; if (hatInstance) { canvasFabric.remove(hatInstance) } hatInstance = new fabric.Image(hatImage, { top: 40, left: screenWidth / 3, scaleX: 100 / hatImage.width, scaleY: 100 / hatImage.height, cornerColor: "#0b3a42", cornerStrokeColor: "#fff", cornerStyle: "circle", transparentCorners: false, rotatingPointOffset: 30 }); hatInstance.setControlVisible("bl", false); hatInstance.setControlVisible("tr", false); hatInstance.setControlVisible("tl", false); hatInstance.setControlVisible("mr", false); hatInstance.setControlVisible("mt", false); canvasFabric.add(hatInstance)}function exportFunc() { document.getElementsByClassName("canvas-container")[0].style.display = "none"; document.getElementById("exportBtn").style.display = "none"; document.getElementById("tip").innerHTML = "长按图片保存或分享"; document.getElementById("change").style.display = "none"; cvs.style.display = "none"; exportImage.style.display = "block"; exportImage.src = canvasFabric.toDataURL({ width: screenWidth, height: screenWidth })}
到此,关于“怎么用java给头像添加一个国旗图案”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
网页标题:怎么用java给头像添加一个国旗图案-创新互联
当前路径:http://azwzsj.com/article/dgehce.html