本文整理汇总了Java中java.awt.image.BufferedImage.TYPE_BYTE_INDEXED属性的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.TYPE_BYTE_INDEXED属性的具体用法?Java BufferedImage.TYPE_BYTE_INDEXED怎么用?Java BufferedImage.TYPE_BYTE_INDEXED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.image.BufferedImage
的用法示例。
在下文中一共展示了BufferedImage.TYPE_BYTE_INDEXED属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndexImage
private BufferedImage createIndexImage(int bpp) {
// calculate palette size
int psize = (1 << bpp);
// prepare palette;
byte[] r = new byte[psize];
byte[] g = new byte[psize];
byte[] b = new byte[psize];
for (int i = 0; i < colors.length; i++) {
r[i] = (byte)(0xff & colors[i].getRed());
g[i] = (byte)(0xff & colors[i].getGreen());
b[i] = (byte)(0xff & colors[i].getBlue());
}
// now prepare appropriate index clor model
IndexColorModel icm = new IndexColorModel(bpp, psize, r, g, b);
return new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
示例2: doTest
public void doTest(int type) {
System.out.println("Test for type " + describeType(type));
BufferedImage src = createTestImage(type);
BufferedImage res = null;
System.out.println("Testing null destination...");
try {
res = op.filter(src, null);
} catch (ImagingOpException e) {
throw new RuntimeException("Test FAILED!", e);
}
if (res == null ||
((src.getType() != BufferedImage.TYPE_BYTE_INDEXED) &&
(res.getType() != src.getType())))
{
throw new RuntimeException("Test FAILED!");
}
System.out.println("Test PASSED.");
}
示例3: getDefaultPalette
private static synchronized byte[] getDefaultPalette() {
if (defaultPalette == null) {
BufferedImage img = new BufferedImage(1, 1,
BufferedImage.TYPE_BYTE_INDEXED);
IndexColorModel icm = (IndexColorModel) img.getColorModel();
final int size = icm.getMapSize();
byte[] r = new byte[size];
byte[] g = new byte[size];
byte[] b = new byte[size];
icm.getReds(r);
icm.getGreens(g);
icm.getBlues(b);
defaultPalette = new byte[size * 3];
for (int i = 0; i < size; i++) {
defaultPalette[3 * i + 0] = r[i];
defaultPalette[3 * i + 1] = g[i];
defaultPalette[3 * i + 2] = b[i];
}
}
return defaultPalette;
}
示例4: blur
public static BufferedImage blur(BufferedImage src) {
BufferedImage bufferedImage = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
int s1 = 7;
int s2 = 7;
float level = .1f / 9f;
float[] filter = new float[s1 * s2];
for (int i = 0; i < s1 * s2; i++) {
filter[i] = level;
}
Kernel kernel = new Kernel(s1, s2, filter);
BufferedImageOp op = new ConvolveOp(kernel);
bufferedImage = op.filter(src, null);
return bufferedImage;
}
示例5: getIndexedImage
protected RenderedImage getIndexedImage() {
IndexColorModel icm = getIndexColorModel();
BufferedImage dst =
new BufferedImage(src.getWidth(), src.getHeight(),
BufferedImage.TYPE_BYTE_INDEXED, icm);
WritableRaster wr = dst.getRaster();
for (int y =0; y < dst.getHeight(); y++) {
for (int x = 0; x < dst.getWidth(); x++) {
Color aColor = getSrcColor(x,y);
wr.setSample(x, y, 0, findColorIndex(root, aColor));
}
}
return dst;
}
示例6: createTestImage
private static BufferedImage createTestImage() {
int w = 100;
int h = 100;
BufferedImage src = new BufferedImage(w, h,
BufferedImage.TYPE_BYTE_INDEXED);
Graphics g = src.createGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, w, h);
g.setColor(Color.green);
g.fillRect(subImageOffset, subImageOffset,
w - 2 * subImageOffset, h - 2* subImageOffset);
g.setColor(Color.blue);
g.fillRect(2 * subImageOffset, 2 * subImageOffset,
w - 4 * subImageOffset, h - 4 * subImageOffset);
g.dispose();
return src;
}
示例7: encodeRLE8Test
private static void encodeRLE8Test() throws IOException {
// create 8bpp image
byte[] r = new byte[256];
r[0] = (byte)0xff;
byte[] g = new byte[256];
g[1] = (byte)0xff;
byte[] b = new byte[256];
b[2] = (byte)0xff;
IndexColorModel icm = new IndexColorModel(8, 256, r, g, b);
BufferedImage bimg = new BufferedImage(100, 100,
BufferedImage.TYPE_BYTE_INDEXED,
icm);
Graphics gr = bimg.getGraphics();
gr.setColor(Color.green);
gr.fillRect(0, 0, 100, 100);
doTest(bimg, "BI_RLE8", ImageWriteParam.MODE_EXPLICIT);
}
示例8: getImageTypeName
static String getImageTypeName(int type) {
switch(type) {
case BufferedImage.TYPE_INT_ARGB:
return "TYPE_INT_ARGB";
case BufferedImage.TYPE_INT_RGB:
return "TYPE_INT_RGB";
case BufferedImage.TYPE_INT_BGR:
return "TYPE_INT_BGR";
case BufferedImage.TYPE_INT_ARGB_PRE:
return "TYPE_INT_ARGB_PRE";
case BufferedImage.TYPE_3BYTE_BGR:
return "TYPE_3BYTE_BGR";
case BufferedImage.TYPE_4BYTE_ABGR:
return "TYPE_4BYTE_ABGR";
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
return "TYPE_4BYTE_ABGR_PRE";
case BufferedImage.TYPE_BYTE_BINARY:
return "TYPE_BYTE_BINARY";
case BufferedImage.TYPE_BYTE_GRAY:
return "TYPE_BYTE_GRAY";
case BufferedImage.TYPE_BYTE_INDEXED:
return "TYPE_BYTE_INDEXED";
case BufferedImage.TYPE_USHORT_555_RGB:
return "TYPE_USHORT_555_RGB";
case BufferedImage.TYPE_USHORT_565_RGB:
return "TYPE_USHORT_565_RGB";
case BufferedImage.TYPE_USHORT_GRAY:
return "TYPE_USHORT_GRAY";
}
return "UNKNOWN";
}
示例9: init
public static void init() {
destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
"dest", "Output Destination Options");
new Screen();
new OffScreen();
if (GraphicsTests.hasGraphics2D) {
if (ImageTests.hasCompatImage) {
compatimgdestroot =
new Group.EnableSet(destroot, "compatimg",
"Compatible Image Destinations");
compatimgdestroot.setHorizontal();
new CompatImg();
new CompatImg(Transparency.OPAQUE);
new CompatImg(Transparency.BITMASK);
new CompatImg(Transparency.TRANSLUCENT);
}
if (ImageTests.hasVolatileImage) {
new VolatileImg();
}
bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
"BufferedImage Destinations");
new BufImg(BufferedImage.TYPE_INT_RGB);
new BufImg(BufferedImage.TYPE_INT_ARGB);
new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
new BufImg(BufferedImage.TYPE_3BYTE_BGR);
new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
new BufImg(BufferedImage.TYPE_BYTE_GRAY);
new CustomImg();
}
}
示例10: ConvertToByteIndexed
public static void ConvertToByteIndexed(Color color, int srcType) {
// setup source image and graphics for conversion.
BufferedImage srcImage = new BufferedImage(width, height, srcType);
Graphics2D srcG2D = srcImage.createGraphics();
srcG2D.setColor(color);
srcG2D.fillRect(0, 0, width, height);
// setup destination image and graphics for conversion.
int dstType = BufferedImage.TYPE_BYTE_INDEXED;
BufferedImage dstImage = new BufferedImage(width, height, dstType);
Graphics2D dstG2D = (Graphics2D)dstImage.getGraphics();
// draw source image into Byte Indexed destination
dstG2D.drawImage(srcImage, 0, 0, null);
// draw into ARGB image to verify individual pixel value.
BufferedImage argbImage = new BufferedImage(width, height,
BufferedImage.TYPE_INT_ARGB);
Graphics2D argbG2D = (Graphics2D)argbImage.getGraphics();
argbG2D.drawImage(dstImage, 0, 0, null);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (color.getRGB() != argbImage.getRGB(i, j)) {
throw new RuntimeException("Conversion from " +
TYPE_TABLE.get(srcType) + " to BYTE_INDEXED is not"
+ " done properly for " + color);
}
}
}
}
示例11: createTestImage
public static BufferedImage createTestImage() {
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_INDEXED);
Graphics g = img.createGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, 100, 100);
g.setColor(Color.white);
g.fillRect(10, 10, 80, 80);
return img;
}
示例12: getImageTypeName
private String getImageTypeName(int t) {
switch(t) {
case BufferedImage.TYPE_INT_RGB:
return "TYPE_INT_RGB";
case BufferedImage.TYPE_INT_BGR:
return "TYPE_INT_BGR";
case TYPE_INT_GRB:
return "TYPE_INT_GRB";
case TYPE_INT_GBR:
return "TYPE_INT_GBR";
case TYPE_INT_RBG:
return "TYPE_INT_RBG";
case TYPE_INT_BRG:
return "TYPE_INT_BRG";
case BufferedImage.TYPE_USHORT_555_RGB:
return "TYPE_USHORT_555_RGB";
case BufferedImage.TYPE_USHORT_565_RGB:
return "TYPE_USHORT_565_RGB";
case TYPE_USHORT_555_GRB:
return "TYPE_USHORT_555_GRB";
case TYPE_USHORT_555_BGR:
return "TYPE_USHORT_555_BGR";
case TYPE_USHORT_565_BGR:
return "TYPE_USHORT_565_BGR";
case BufferedImage.TYPE_3BYTE_BGR:
return "TYPE_3BYTE_BGR";
case TYPE_3BYTE_RGB:
return "TYPE_3BYTE_RGB";
case TYPE_3BYTE_GRB:
return "TYPE_3BYTE_GRB";
case BufferedImage.TYPE_BYTE_INDEXED:
return "TYPE_BYTE_INDEXED";
case TYPE_4BPP_INDEXED:
return "TYPE_BYTE_INDEXED (4bpp)";
default:
throw new IllegalArgumentException("Unknown image type: " + t);
}
}
示例13: init
public static void init() {
pixelroot = new Group("pixel", "Pixel Access Benchmarks");
pixeloptroot = new Group(pixelroot, "opts", "Pixel Access Options");
doRenderTo = new Option.Toggle(pixeloptroot, "renderto",
"Render to Image before test",
Option.Toggle.Off);
doRenderFrom = new Option.Toggle(pixeloptroot, "renderfrom",
"Render from Image before test",
Option.Toggle.Off);
// BufferedImage Sources
bufimgsrcroot = new Group.EnableSet(pixelroot, "src",
"BufferedImage Sources");
new BufImg(BufferedImage.TYPE_BYTE_BINARY, 1);
new BufImg(BufferedImage.TYPE_BYTE_BINARY, 2);
new BufImg(BufferedImage.TYPE_BYTE_BINARY, 4);
new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
new BufImg(BufferedImage.TYPE_BYTE_GRAY);
new BufImg(BufferedImage.TYPE_USHORT_555_RGB);
new BufImg(BufferedImage.TYPE_USHORT_565_RGB);
new BufImg(BufferedImage.TYPE_USHORT_GRAY);
new BufImg(BufferedImage.TYPE_3BYTE_BGR);
new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
new BufImg(BufferedImage.TYPE_INT_RGB);
new BufImg(BufferedImage.TYPE_INT_BGR);
new BufImg(BufferedImage.TYPE_INT_ARGB);
// BufferedImage Tests
bufimgtestroot = new Group(pixelroot, "bimgtests",
"BufferedImage Tests");
new BufImgTest.GetRGB();
new BufImgTest.SetRGB();
// Raster Tests
rastertestroot = new Group(pixelroot, "rastests",
"Raster Tests");
new RasTest.GetDataElements();
new RasTest.SetDataElements();
new RasTest.GetPixel();
new RasTest.SetPixel();
// DataBuffer Tests
dbtestroot = new Group(pixelroot, "dbtests",
"DataBuffer Tests");
new DataBufTest.GetElem();
new DataBufTest.SetElem();
}
示例14: createFromBufferedImageType
/**
* Returns an <code>ImageTypeSpecifier</code> that encodes
* one of the standard <code>BufferedImage</code> types
* (other than <code>TYPE_CUSTOM</code>).
*
* @param bufferedImageType an int representing one of the standard
* <code>BufferedImage</code> types.
*
* @return an <code>ImageTypeSpecifier</code> with the desired
* characteristics.
*
* @exception IllegalArgumentException if
* <code>bufferedImageType</code> is not one of the standard
* types, or is equal to <code>TYPE_CUSTOM</code>.
*
* @see java.awt.image.BufferedImage
* @see java.awt.image.BufferedImage#TYPE_INT_RGB
* @see java.awt.image.BufferedImage#TYPE_INT_ARGB
* @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
* @see java.awt.image.BufferedImage#TYPE_INT_BGR
* @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
* @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
* @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
* @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
* @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
* @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
* @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
* @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
* @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
*/
public static
ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
return getSpecifier(bufferedImageType);
} else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
} else {
throw new IllegalArgumentException("Invalid BufferedImage type!");
}
}