I am working on a project that involves pattern detection. I have to scale the input images to a specific size and test for pixel colour.
I tried to take in a java.awt.Image so I could resize it, then convert it to BufferedImage to test for the RGB value for each independent pixel. However, casting BufferedImage to Image does not work.
Since java.awt.Image cannot access the color value of each individual pixel, I have to use the .getRBG functions of a BufferedImage. However, I have to take in a java.awt.Image because BufferedImage cannot be resized. I did some research about resizing the BufferedImage but all the result I found is about resizing it on screen, but not the actual image. I am NOT trying to display the BufferedImage on screen, I am trying to access the colour value of each pixel on an image.
These are the ways that could fix my issue: Please suggest a way to...
- Scale a BufferedImage (that doesn't involve drawing on the screen, just resizing the BufferedImage itself)
or
- Access the colour value of a pixel in java.awt.Image
Image img = ImageIO.read(inputFile).getScaledInstance(400, 400, 0);
BufferedImage scaledImage = (BufferedImage)img;
The following code does not compile because BufferedImage cannot be cast to java.awt.Image