如何获得我单击的图像像素的颜色? [英] How to get the color of the image pixel on which I clicked?

查看:77
本文介绍了如何获得我单击的图像像素的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像,具体地说,它是从 Image.asset()加载的。

I have an image, specifically, it's loaded in from Image.asset().

它包装在扩展小部件中,并且具有自己的上下文。

It's wrapped in an extended widget, and has its own context.

我可以单击它,并获得单击的本地位置(图像/上下文的x / y本地)。

I can click on it, and get the local position on which I clicked (x/y local to the image/context).

从这一点上我要做的就是获取一些信息(特别是颜色和Alpha /不透明度,但是颜色是关键)。我真的只想要那个上下文的图像信息,以及能够明确地说出我需要字节#的能力。或我需要来自X和Y的像素信息。我觉得它已经存在于Flutter中,因为它在许多(大多数?)具有丰富UI的其他平台中都是微不足道的。

All I want to do from that point is get some information (specifically, color and alpha/opacity, but color is key). I really just want THAT context's image information, and the ability to definitively say "I need byte #" or "I need pixel info from X and Y". I feel like this HAS to exist in Flutter as it's pretty trivial in many (most?) other platforms with a rich UI.

我错过了一些简单的东西,或者这在这方面很难吗?

Am I missing something simple, or is this just harder in this platform than I'm mentally allowing for?

还是应该加载html库并在其中执行所需的操作?

Or should I load the html library and do what I need in there?

谢谢!

(根据历史,我流利于iOS开发,C#和.Net,HTML和画布工作以及许多其他平台,这些年来我想不起来了,等等,但是对Flutter来说还很陌生,因为我们正在紧急重写Trigger中拥有的应用程序,现在它的运行情况再也不好了。谢谢:)

(by way of history, I'm fluent in iOS dev, C# and .Net, HTML and canvas work, and a host of other platforms over more years than I want to remember, etc, but fairly new to Flutter because we're doing an emergency rewrite of an app we had in Trigger, which is not behaving well any more. Thanks.) :)

推荐答案

我不知道您是否还在寻找解决方案。

I don't know if you are still looking for a solution.

我刚刚做了这个原型对您来说...希望已经足够清楚了。

I just made this prototype for you... hope is clear enough.

这是一个视频 o f。

顺便说一句,图像库有很多方法可以解决您需要的...如果需要的话,像素值可以通过列表,因此您可以解决KML颜色并将列表视为网格(行,列数学以查找索引)。

By the way, the image library has plenty of methods to workaround what you need... in case you need it, and pixel values are accessible as List, so you can workaround the KML colors and treat the list as a grid (rows, cols math to find the index).

警告:库使用其他颜色格式(#AABBGGRR),但可以轻松转换。

Warning: the library uses a different color format (#AABBGGRR), but can be converted easily though.

更新:

我根据注释中的限制制作了v2,但将原始代码段更改为显示两种方法。
这个生成一个您想要的任何小部件的快照(因此需要变换/着色/盒装配件/您在屏幕上呈现的所有内容)。

I made a v2 based on the limitations noted in the comments, but change the original snippet to show both approaches. This one generates a snapshot of whatever widget you want (so it takes transforms/colorization/box fittings/whatever u have rendered on screen).

为您提供很多功能,如果您不必经常对小部件进行动画处理或使之无效。

Gives you a lot of versatility, if you don't have to animate or invalidate the widget often.

检查 demo在YouTube中

这篇关于如何获得我单击的图像像素的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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