惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
Simon Willison's Weblog
Simon Willison's Weblog
B
Blog
V
Visual Studio Blog
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
S
SegmentFault 最新的问题
博客园 - 司徒正美
博客园 - 【当耐特】
T
Tenable Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium
S
Secure Thoughts
Hugging Face - Blog
Hugging Face - Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
PCI Perspectives
PCI Perspectives
H
Hackread – Cybersecurity News, Data Breaches, AI and More
阮一峰的网络日志
阮一峰的网络日志
P
Privacy International News Feed
N
News and Events Feed by Topic
H
Hacker News: Front Page
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure
Google Online Security Blog
Google Online Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Heimdal Security Blog
Project Zero
Project Zero
C
CERT Recently Published Vulnerability Notes
MyScale Blog
MyScale Blog
AI
AI
月光博客
月光博客
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
WordPress大学
WordPress大学
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CXSECURITY Database RSS Feed - CXSecurity.com
Spread Privacy
Spread Privacy
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
SecWiki News
SecWiki News
C
Cisco Blogs
The Last Watchdog
The Last Watchdog

vivaxy's Blog

SameSite Cookies 解读 - vivaxy's Blog VSCode Conventional Commits 插件 - vivaxy's Blog VSCode Conventional Commits Extension - vivaxy's Blog How Babel Is Built - vivaxy's Blog 一步一步解码 PNG 图片 - vivaxy's Blog Babel 的工程化实现 - vivaxy's Blog Decoding A PNG Image with JavaScript Step by Step Comprehensive Image Processing on Browsers Use npm Registry to Restric Installing Client Alfred 4 Workflow Open in VSCode Git Tag And Push Git Tag 基于 Custom Elements 的组件化开发 - vivaxy's Blog JavaScript PNG 图片编码和解码 - vivaxy's Blog 如何在多个模块中共享异步数据 - vivaxy's Blog JavaScript 函数式编程初窥 - vivaxy's Blog 用纯 CSS 实现弹窗 - vivaxy's Blog 在浏览器中使用 JavaScript 模块 - vivaxy's Blog Karabiner Elements Hyper 改键设置 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog Levenshtein 距离 - vivaxy's Blog
浏览器图像转换手册 - vivaxy's Blog
vivaxy · 2019-11-08 · via vivaxy's Blog

介绍

图像可以用多种不同的类型数据表示,本文将它们归纳为 5 种类型:DOM,URL,FileImageData 和 Buffer。

图像的数据类型

DOM

<img>

<img> 元素从 URL(Data URL,HTTP URL 或 Object URL)加载图像。

<canvas>

<canvas> 元素通过 canvas API drawImage 来获取 <img> 元素上的图像数据。

URL

Data URL

Data URL 带有 base64 编码的图像数据。可以从 Data URL 数据中解码出图像的二进制数据。Data URL 数据的大小比原始的二进制数据大一些。

HTTP URL

HTTP URL 代表存储在服务器上的图像。HTTP URL 用于从服务器获取图像数据。

Object URL

Object URL 用来代表存储在浏览器内存中的 FileBlob 对象。Object URL 可以由createObjectURL API 来创建,并由 revokeObjectURL API 释放。

文件

Blob

Blob 是带有二进制数据的类文件对象。它包含一个只读的 size 属性和一个只读的 type 属性。你可以通过 slicestreamtext 等方法来读取二进制数据。

File

一个 File 对象是一个特殊的 Blob 对象。除了 Blob 的属性和方法外,File 对象还包含 lastModifiedname 等属性。

ImageData

一个 ImageData 对象是一个 JavaScript 对象,包含 widthheightdata 属性,分别表示图像宽度,高度和像素数据。 data 属性是一个一维数组,包含 R,G,B,A,R,G,B,A 这样格式的数据。每个 R,G,B,A 代表一个像素。可以通过 <canvas> API createImageDataImageData 构造函数来创建 ImageData

Buffer

ArrayBuffer

ArrayBuffer 是在浏览器中唯一一种访问二进制数据的方法。ArrayBuffer 代表图像的原始二进制数据缓冲区。我们无法读取和写入 ArrayBuffer ,只能将 ArrayBuffer 转换为 DataViewTypedArray 来读取和写入二进制数据。

Buffer

Buffer 是 Node.js 中特殊的一种 Uint8Array,Node.js 对其进行了一些优化。

ArrayBufferDataView,TypedArray 和 Buffer 之间转换

如何在 `ArrayBuffer`,`DataView`,TypedArray 和 `Buffer` 之间转换

在 DOM,URL,Blob(File),ImageData 和 Buffer 之间转换

如何在 DOM,URL,Blob(File),`ImageData` 和 Buffer 之间转换

参考资料