在BufferedImage的int []像素数组中工作 [英] Working in a BufferedImage's int[] pixels array

查看:193
本文介绍了在BufferedImage的int []像素数组中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 setRGB getRGB 方法处理BufferedImage时,我注意到两件事:

When working with BufferedImage using the setRGB and getRGB methods, I noticed two things:


  1. setRGB getRGB 方法在某些系统上可能会非常慢(比修改int []数组慢两个数量级) )。

  1. the setRGB and getRGB methods can be incredibly slow on some systems (as much as two orders of magnitude slower than modifiyng the int[] array).

无法保证 setRGB 后面的 getRGB 会返回相同的像素你通过了

there are no guarantee that a getRGB following a setRGB will give back the same pixel you passed

最后一点基本上是从 setRGB 的JavaDoc中清楚看到的,状态:

This last point is basically pretty clear from the JavaDoc of setRGB, which states:


...对于带有IndexColorModel的图像,
选择最近颜色的索引为

...For images with an IndexColorModel, the index with the nearest color is chosen.

看到我可以直接在BufferedImage的int []像素中工作,我可以通过这样做来访问,例如:

Seen I can work directly in a BufferedImage's int[] pixels, which I can access to by doing, for example:

 int[] a = ((DataBufferInt) tmp.getRaster().getDataBuffer()).getData();

我想知道:直接操作<$ c $中的像素是否有任何已知的缺点/陷阱c> int [] ?

推荐答案

getData()的全部内容让您可以访问支持int数组正是为了这个优化,所以最有可能的好处大于缺点。

The whole point of getData() giving you access to the backing int array is precisely for this optimization, so the benefits most likely outweigh the drawbacks.

缺点取决于你如何使用缓冲图像。如果你在编辑时将它绘制到屏幕上,你可能会在屏幕上遇到一些瑕疵(比如没有及时着色的像素),在这种情况下你应该考虑双缓冲(这涉及复制整个图像)每次刷新)。

The drawbacks depend on how you're using the buffered image. If you're drawing it to the screen while you're editing it, you may encounter some artifacts on the screen (like pixels not colored in time), in which case you should consider double buffering (which does involve copying over the entire image for every refresh).

这篇关于在BufferedImage的int []像素数组中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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