下面列出了怎么用java.awt.image.ByteLookupTable的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
byte[][] data = new byte[1][10];
ByteLookupTable lut = new ByteLookupTable(0, data);
RasterOp op = new LookupOp(lut, null);
int[] bandOffsets = {0};
Point location = new Point(0, 0);
DataBuffer db = new DataBufferByte(10 * 10);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
10, 10, 1, 10,
bandOffsets);
Raster src = Raster.createRaster(sm, db, location);
op.filter(src, null); // this used to result in NullPointerException
}
private static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url)
.map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(MainPanel::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (i * .2f);
}
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
private static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url).map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(MainPanel::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (i * .2f);
}
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
private static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url)
.map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(MainPanel::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (i * .5);
}
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
public static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url)
.map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(ImageUtil::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
IntStream.range(0, b.length).forEach(i -> b[i] = (byte) (i * .5));
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
/**
* Reverse image color components, leave alpha unchanged.
*/
private static LookupTable createReverseTable() {
byte[] data = new byte[256];
for (int i = 0; i < 256; i++) {
data[i] = (byte) (255 - i);
}
return new ByteLookupTable(0, data);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}