您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么用java給頭像添加一個(gè)國(guó)旗圖案”,在日常操作中,相信很多人在怎么用java給頭像添加一個(gè)國(guó)旗圖案問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么用java給頭像添加一個(gè)國(guó)旗圖案”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
代碼如下
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 = "長(zhǎng)按圖片保存或分享"; document.getElementById("change").style.display = "none"; cvs.style.display = "none"; exportImage.style.display = "block"; exportImage.src = canvasFabric.toDataURL({ width: screenWidth, height: screenWidth })}
到此,關(guān)于“怎么用java給頭像添加一個(gè)國(guó)旗圖案”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。