色彩还原(Java 中)
我想找到一种方法来拍摄 JPEG(或 GIF/PNG)图像并将颜色数量减少到例如 20。有人可以推荐一些库或其他参考吗? 也欢迎其他语言的源代码。
I would like to find a way to take JPEG (or GIF/PNG) images and reduce the amount of colors to e.g. 20. Could someone recommend some library or other reference? Also source codes in other languages are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
JAI(Java 高级成像 API)可以完成这项工作,但它有一些缺点。
该 API 远非易于使用,特别是如果您关心内存占用...
恕我直言,Java 不是成像任务的最佳平台。
您可以尝试 ImageMagick,这是一个很棒的命令行工具,Flickr 等热门网站都在使用。 您可以使用命令行 (Runtime.exec()) 或 Jmagick 它是 ImageMagick 的 Java 桥接器
JAI (Java Advanced Imaging API) would do the work but it has some drawbacks.
The API is far from being easy to use, especially if you care about memory footprint...
IMHO Java is not the best platform for imaging tasks.
You might try ImageMagick, a wonderful command line tool, used by popular sites such as Flickr. You can integrate ImageMagick in your java application using the command line (Runtime.exec()) or Jmagick which a java bridge to ImageMagick
这看起来是一个基于 ImageMagick 的简单 java 实现:
http://gurge.com /amd/java/quantize/index.html
This seems like a simple implementation in java, based on ImageMagick:
http://gurge.com/amd/java/quantize/index.html
查看图像过滤器 http://www.jhlabs.com/ip/过滤器/index.html。 QuantizeFilter 似乎可以满足您的要求。
Take a look at the image filters at http://www.jhlabs.com/ip/filters/index.html. The QuantizeFilter seems to do what you want.
寻找有关颜色量化的算法,尤其是中值切割。 您会发现许多带有这些关键字的示例。 为您执行此操作的库包括 ImageMagick,它具有多种语言的绑定。 JMagick 是 Java 风格。
Look for algorithms on color quantization, especially median cut. You'll find many examples with those keywords. Libraries to do this for you include ImageMagick which has bindings for many languages. JMagick is the Java flavor.
JAI API 是必经之路。 如今的 JVM 性能非常接近汇编代码。 我知道我已经做到了。
JAI API is the way to go. WIth today's JVM performance is very close to assembler code. I know I've done it.
查看 Java 高级成像 API。 该 API 中实现了许多用于减少颜色的算法。
Take a look at the Java Advanced Imaging API. There are a number of algorithms implemented in that API for doing color reduction.