Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use java to add a national flag pattern to the avatar

Shulou Source: shulou.com Published: 2022-06-03 14:17:40 10月02日 Update

This article mainly introduces "how to use java to add a national flag pattern to the avatar". In the daily operation, I believe that many people have doubts about how to use java to add a national flag pattern to the avatar. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful for everyone to answer the doubt of "how to use java to add a national flag pattern to the avatar". Next, please follow the editor to study!

The code is as follows

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 file 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") [xss_clean] = "long click to save or share" Document.getElementById ("change"). Style.display = "none"; cvs.style.display = "none"; exportImage.style.display = "block"; exportImage.src = canvasFabric.toDataURL ({width: screenWidth, height: screenWidth})} this is the end of the study on "how to use java to add a national flag pattern to the avatar", hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Flag pattern avatar study more help practical next code picture article method theory knowledge article website material follow question easy to use Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno Shulou Technology Shulou Tech Info vpn