什么是 Base64 编码器/解码器?
此工具将文本和文件编码为 Base64 格式,并将 Base64 字符串解码回可读内容。Base64 是一种二进制到文本的编码方案,广泛用于 Web 开发、电子邮件系统和 API。所有操作都在浏览器中运行,不会向任何服务器发送数据。
如何将文本编码为 Base64
确保模式设置为编码。在输入区域输入或粘贴文本。Base64 编码结果立即显示在输出面板中。点击复制按钮将输出复制到剪贴板。
如何将 Base64 解码为文本
将模式切换为解码。将 Base64 字符串粘贴到输入区域。解码后的纯文本显示在输出中。如果输入不是有效的 Base64,会显示错误消息。
如何将图像转换为 Base64
将图像文件拖放到上传区域,或点击选择文件。工具会生成包含 Base64 编码图像的 data URL(格式为 data:image/[type];base64,...),可以直接在 HTML img 标签或 CSS 中使用。
- Supports all file types including images, PDFs, and documents.
- Image files display an inline preview below the upload area.
- The full data URL is shown in the output and can be copied.
Base64 编码的常见用例
- 在 HTML 或 CSS 中嵌入小图像
- 在 JSON 或 XML 中传输二进制数据
- 在基于文本的协议中编码附件
- 在 URL 中存储小型数据
- 创建 data URL 用于内联资源
Tips for Working with Base64
Keep in mind that Base64 increases data size by about a third. For large files, it is usually better to serve them as separate resources rather than embedding them inline. Base64 is ideal for small assets like icons and thumbnails where reducing HTTP requests matters more than payload size.