Which amongst PixelGrabber vs getRGB is faster?

荒凉一梦 提交于 2021-01-28 12:00:34

问题


I was trying to implement Hill Cipher algorithm on an image by grabbing its pixels. And it turns out that small images were loading fine.

But with bigger images (8MP or 12MP), the loading is slow; and as a result writing the image is slow too.

I was grabbing each pixel using bufferedImage.getRGB(x,y), modifying it using the algorithm, and writing the pixels simultaneously using bufferedImage.setRGB(x,y,rgb).

Now, I need some suggestions to make the loading/writing faster. I was wondering if PixelGrabber would be any better?


回答1:


getRGB/setRGB are very slow, because they do a lot of colorspace-checking and color-converting every time you call them. Definitely not the way to to any image-manipulation, considering the number of pixels in a typical image.

Getting the raw image data into arrays via the old PixelGrabber or via BufferedImage.getRaster() is harder (you have to understand a few concepts) but runs much faster.



来源:https://stackoverflow.com/questions/10954389/which-amongst-pixelgrabber-vs-getrgb-is-faster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!