久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將畫布解碼為 dataURL

Decoding a canvas todataURL(將畫布解碼為 dataURL)
本文介紹了將畫布解碼為 dataURL的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在使用使用 canvas 的 todataurl() 方法創建的數據時遇到困難.目前,我的代碼將結果數據發送到我的 php 服務器,該服務器使用 file_put_contents() 方法創建一個文件來存儲該數據.現在,如果我將文件中產生的亂碼剪切并粘貼到圖像標簽 src 中,它可以正常工作并正確顯示,因此我認為到目前為止一切都很好.

I'm having difficulty using data created with canvas's todataurl() method. Currently my code sends the resulting data to my php server which uses the file_put_contents() method to create a file to store that data. Now if I cut and paste the resulting gibberish from the file into an image tag src it works fine and displays properly so I assume so far everything is peachy.

但是當我嘗試在 JS 中使用代碼時,我一直遇到問題.我試過 php 的 base64_decode 方法,但一直收到損壞的文件.我找到了這個代碼:

But I keep running into issues when I try to use the code in JS. I've tried php's base64_decode method but kept getting currupt files. I found this code:

<?php
  $encodedData = str_replace(' ','+',$encodedData);
  $decocedData = base64_decode($encodedData);

并且仍然有損壞的文件.理想情況下,我想用它創建一個 .png 文件,但我只想在 JS 中再次處理數據文件.非常感謝任何幫助.

and still got currupted files. Ideally I'd like to create a .png file with it but I'd settle for just processing the data file again in JS. Any help greatly appreciated.

推薦答案

看來您必須通過 toDataURL() 函數刪除預先添加到圖像數據的標題.在客戶端,您可以像這樣去除標題:

It seems you have to get rid of the header that is prepended to the image data by the toDataURL() function. On the client side you can strip off the header like this:

..
var data=canvas.toDataURL();
var output=data.replace(/^data:image/(png|jpg);base64,/, "");
// now send "output" to the server
..

在服務器端使用這個:

<?php
    $decocedData = base64_decode($encodedData);
?>

這篇關于將畫布解碼為 dataURL的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 一级黄色片免费 | 国产一区二区三区四区 | 一区中文字幕 | 欧美成人a∨高清免费观看 欧美日韩中 | 成人免费视频网站在线看 | 日韩欧美精品在线 | 91影院 | 久草在线免费资源 | 美女黄网站| 国产精品国产三级国产aⅴ入口 | 国产精品欧美精品 | 日韩一 | 亚洲人免费视频 | 久久国产精品-国产精品 | av看片网站 | 三区四区在线观看 | 九九热精品在线 | 欧美片网站免费 | 亚洲一区二区电影网 | 99tv| 九九久久久 | 日韩在线看片 | 欧美在线一区二区三区 | 日韩精品免费视频 | 日本三级电影在线观看视频 | 在线免费观看视频你懂的 | 欧美精品日韩精品国产精品 | 九九热精品在线视频 | a级黄色片在线观看 | 免费观看av网站 | 欧美xxxx色视频在线观看免费 | 精品免费国产视频 | 精品欧美一区二区精品久久久 | 99re视频在线 | 亚洲一区二区三区四区在线观看 | 国产一区二区久久 | 亚洲图片一区二区三区 | 在线一区 | 国产精品一区二区无线 | 亚洲一区中文字幕 | 欧美精品久久久 |