You have a couple options:
Add a constructor to the extended class that accepts a
BufferedImage
and sets everything appropriately.public class ExtendedBufferedImage extends BufferedImage{ public ExtendedBufferedImage(BufferedImage image){ //set all the values here } //add your methods below }
This one seems like a lot of work and potential for issues. If you forget to set some variable you could introduce some weird bugs, or lose information you need.
Create a wrapper class that has an instance of a
BufferedImage
, and then add your methods in.public class ExtendedBufferedImage{ private BufferedImage image; public ExtendedBufferedImage(BufferedImage image){ this.image = image; } //add your methods below }
This is pretty reasonable, and is not to diffcult. Make the
BufferedImage
public or add a getter method and you can get the actualBufferedImage
out of it if you need that.Create a Utility class that has your methods as being static and pass in the
BufferedImage
as a parameter.public class BufferedImageUtil{ public static int getRed(BufferedImage image, int x, int y) { return (image.getRGB(x, y) >> 16) & 0xFF; } //add your other methods }
Some people don't like utility Classes, but I kind of like them for things like this. If you are going to use these methods all over the place, I think this is a good option.
Personally I would go the utility class route, but if you don't like those then wrapping it as done in option 2 is just as functional.