跳至主要內容

對字串進行 base64 編碼 (string.base64_encode)

聲明

b64 文字 = string.base64_encode(資料內容)

參數

  • 資料內容
    字串型,原始字串

回傳值

  • b64 文字
    文字型,返回字串的 base64 編碼文字

說明

對字串(或二進位資料塊)進行 Base64 編碼
關鍵詞:圖片 Base64、檔案 Base64、資料 Base64、二進位 Base64

範例

-- 取屏幕區域 png 格式數據進行 base64 編碼
b64s = screen.image(0, 0, 100, 100):png_data():base64_encode()

-- 讀取文件數據並進行 base64 編碼
b64s = file.reads('/var/mobile/1.png'):base64_encode()

:上述代碼中使用了非本章函式 screen.image:png_datafile.reads

更多範例

參考 本章末尾的綜合範例