Thanks aioobe, I looked at the WritableRaster class and found the getPixels function that does exactly what I need, the end result:
public int[] getImageDataPort(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); int[] ret = null; ret = image.getRaster().getPixels(0, 0, width, height, ret); return ret; }
The only problem that may arise is that image.getType not a type that supports alpha compared to the question code, which leads to a smaller int[] ret , but you can simply convert the image type with:
public BufferedImage convertType(BufferedImage image,int type){ BufferedImage ret = new BufferedImage(image.getWidth(), image.getHeight(), type); ColorConvertOp xformOp = new ColorConvertOp(null); xformOp.filter(image, ret); return ret; }
source share