从SVG rect元素获取每个像素的RGB值 [英] To get a RGB value for each pixel from SVG rect element

查看:294
本文介绍了从SVG rect元素获取每个像素的RGB值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取svg rect元素中每个像素的颜色值.在画布中,我们可以通过getImageData(x,y,width,height)方法获取它.

I need to get the color value for each pixel in svg rect element.In canvas we can get it through the method getImageData(x,y,width,height).

在svg中,有什么方法可以做到?如果是,请提供一些工作示例.

In svg,is there any way to do it??If so please give some working examples.

推荐答案

如果您创建一个独立的SVG文件,并通过图像元素将其包含在文档中,例如html <img>元素,则可以通过 drawImage ,您已经知道如何从画布中提取颜色值.

If you create a standalone SVG file and include that in your document via an image element e.g. a html <img> element then you can copy the image data into canvas via drawImage and you already know how to extract colour values from canvas.

这种间接途径是唯一的方法.

This indirect route is the only way.

这篇关于从SVG rect元素获取每个像素的RGB值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆