问题
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