This repository has been archived by the owner on Nov 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Falkreon edited this page Jul 24, 2021
·
2 revisions
ImageData is the main focus of this library. It's a 32-bit ARGB image in the sRGB colorspace. Unlike BufferedImage, ImageData is not capable of different color depths, colorspaces or gamuts, element orders, or bitplaning. It's made for fast access on modern machines, and straightforward upload to GL, DX, or Java2D.
ImageData are obtained in a few ways: Just like BufferedImage, you can construct an empty, transparent image:
ImageData blankImage = new ImageData(100, 200);
You can also use ImageIO:
ImageData testImage = PNGImageLoader.load(new FileInputStream(new File("test.png")));
Once you have an image, you can edit it directly by setting pixels:
ImageData missingno = new ImageData(256, 256);
for(int y=0; y<256; y++) {
for(int x=0; x<256; x++) {
int p = (x/32 + y/32) % 2;
if (p==0) {
missingno.setPixel(x, y, 0xFF_000000);
} else {
missingno.setPixel(x, y, 0xFF_FF00FF);
}
}
}
If you need more complex tasks, including image compositing, use an ImageEditor:
//You can use your main class's classLoader to grab resource InputStreams suitable for PNGImageLoader from the jar
ImageData a = PNGImageLoader.load(TestClass.class.getClassLoader().getResourceAsStream("image/a.png"));
ImageData b = PNGImageLoader.load(TestClass.class.getClassLoader().getResourceAsStream("image/b.png"));
ImageEditor bEditor = ImageEditor.edit(b);
bEditor.drawImage(a, 10, 10, BlendMode.LINEAR_BURN, 0.5); //blend with LINEAR_BURN and apply with 50% opacity
//Opacity blends are applied using a high-quality linear colorspace method to avoid haloes
//No close or dispose is needed here, the operation is complete at the end of the method call.