Offset an Image or color channel position.
The rgbOffset package enables you to offset the X & Y position of inputted image pixels or the pixel values for individual RGB channels. This is a common effect in graphics programs like Adobe Photoshop and GIMP.
This package does not require JavaFX. It is built using the Java AWT API only.
No Offset | Offset X= 256, Y= -128 | Offset RGB channels | Offset just Red X&Y = 32 |
---|---|---|---|
The docker image is available here.
docker pull aabalke33/java-rgboffset
Requires "-it" and "-v" flags to make it interactable and to mount a host directory to be accessible to the container.
docker run -it -v C:\Users\User\Desktop:/tmp/files <image>
# Makes Desktop files accessible to container inside /tmp/files directory.
The offset methods take image data expressed as a BufferedImage. An example is provided below for a standard method of creating and inputting BufferedImage parameters.
Input Methods are overloaded. Allowing for method calls with channel values and without. If channel values are not inputted, it is assumed to be 0.
// Without Channel Values
BufferedImage image = rgbOffset.offset(image, xOffset, yOffset);
// With Channel Values
BufferedImage image = rgbOffset.offset(image, xOffset, yOffset, rxOffset, ryOffset, gxOffset, gyOffset, bxOffset, byOffset);
- Position offset values are measured in pixels
- Has to be 8 Bit per Channel Image.
import rgbOffset.offset;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
// Set Variable Names
BufferedImage image = ImageIO.read(new File("input.jpg"));
int xOffset = 100; // Moves image right 100 pixels
int yOffset = 1000; // Moves image down 1000 pixels
// Create Offset Image
BufferedImage image = rgbOffset.offset(image, xOffset, yOffset);
// Export Offset Image
ImageIO.write(image, "jpg", new File("output.jpg"));
}
}
- Provide measurements other than pixels, perhaps a percentage of the total image size
- Support 16bit and 24bit images
- Original version that was not posted used ArrayLists to store color channel data. It was not faster than this implementation and used 3.3x the physical memory. Using BufferedImages is WAY better.