我正在编写一些 Javascript 代码,该代码使用 Photoshop 嵌入的路径创建图像的 alpha 蒙版。IMG 标记的 onload 处理程序将调用剪辑(this)。该函数加载图像的源文件并扫描它。这是设置:
function clip(img) {
var xhr = new XMLHttpRequest();
xhr.open('GET', img.src, true);
xhr.responseType = 'arraybuffer';
xhr.target = img;
xhr.onload = function(e) {
var bytes = new Uint8Array(this.response);
var p = findPhotoshopSegment(bytes);
if(p) {
var paths = parse8BIMData(bytes, p);
/* ... replaces IMG with SVG tag ... */
}
};
xhr.send();
}
您可以在http://flaczki.net46.net/JPEG/SVG.html上查看实际代码
目前,它仅适用于 Firefox、Chrome 和 Safari。它在 IE9 中不起作用。浏览器支持 SVG 但不支持 Uint8Array。有什么解决方法吗?