本文整理汇总了Java中java.awt.image.BufferedImage.TYPE_CUSTOM属性的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.TYPE_CUSTOM属性的具体用法?Java BufferedImage.TYPE_CUSTOM怎么用?Java BufferedImage.TYPE_CUSTOM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.image.BufferedImage
的用法示例。
在下文中一共展示了BufferedImage.TYPE_CUSTOM属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
/** {@inheritDoc} */
public BufferedImage convert(Reference<BufferedImage> ref, int type)
throws ImageIOException {
if (ref == null) throw new IllegalArgumentException();
// NB: We don't bother clearing the ref because this method requires
// that the source and destination images exist simultaneously.
final BufferedImage src = ref.obj;
// we can't create images of TYPE_CUSTOM
if (type == BufferedImage.TYPE_CUSTOM) throw new IllegalArgumentException();
final int w = src.getWidth();
final int h = src.getHeight();
final BufferedImage dst = new BufferedImage(w, h, type);
final Graphics2D g = dst.createGraphics();
g.drawImage(src, 0, 0, null);
g.dispose();
return dst;
}
示例2: createFromRenderedImage
/**
* Returns an <code>ImageTypeSpecifier</code> that encodes the
* layout of a <code>RenderedImage</code> (which may be a
* <code>BufferedImage</code>).
*
* @param image a <code>RenderedImage</code>.
*
* @return an <code>ImageTypeSpecifier</code> with the desired
* characteristics.
*
* @exception IllegalArgumentException if <code>image</code> is
* <code>null</code>.
*/
public static
ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
if (image == null) {
throw new IllegalArgumentException("image == null!");
}
if (image instanceof BufferedImage) {
int bufferedImageType = ((BufferedImage)image).getType();
if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
return getSpecifier(bufferedImageType);
}
}
return new ImageTypeSpecifier(image);
}
示例3: createFromRenderedImage
/**
* Returns an {@code ImageTypeSpecifier} that encodes the
* layout of a {@code RenderedImage} (which may be a
* {@code BufferedImage}).
*
* @param image a {@code RenderedImage}.
*
* @return an {@code ImageTypeSpecifier} with the desired
* characteristics.
*
* @exception IllegalArgumentException if {@code image} is
* {@code null}.
*/
public static
ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
if (image == null) {
throw new IllegalArgumentException("image == null!");
}
if (image instanceof BufferedImage) {
int bufferedImageType = ((BufferedImage)image).getType();
if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
return getSpecifier(bufferedImageType);
}
}
return new ImageTypeSpecifier(image);
}
示例4: convertImage
/**
* this method convert supplied image to suitable type
* it is needed because we need bytes of array so TYPE_INT images must be
* converted to BYTE_BGR or so
* @param originalImage loaded from file-chooser
* @return
*/
public BufferedImage convertImage(BufferedImage originalImage) {
int newImageType = originalImage.getType();
/**
* Converting int to byte since byte array is needed later to modify
* the image
*/
if (newImageType == BufferedImage.TYPE_INT_RGB
|| newImageType == BufferedImage.TYPE_INT_BGR) {
newImageType = BufferedImage.TYPE_3BYTE_BGR;
} else if (newImageType == BufferedImage.TYPE_INT_ARGB ||
newImageType == BufferedImage.TYPE_CUSTOM) {
newImageType = BufferedImage.TYPE_4BYTE_ABGR;
} else if (newImageType == BufferedImage.TYPE_INT_ARGB_PRE) {
newImageType = BufferedImage.TYPE_4BYTE_ABGR_PRE;
} else {
// no need to convert original image
return null;
}
BufferedImage newImage = new BufferedImage(originalImage.getWidth(),
originalImage.getHeight(), newImageType);
Graphics g = newImage.getGraphics();
g.drawImage(originalImage, 0, 0, null);
g.dispose();
return newImage;
}
示例5: analyseAndSetOpenGLParameters
/**
* Analyes the specified image and sets the proper openGLImage-values.
* @return <code>true</code> if the image foramt has successfully detected.
*/
public boolean analyseAndSetOpenGLParameters() {
boolean retValue = true;
String errorString = "";
try {
switch(image.getType()) {
case BufferedImage.TYPE_4BYTE_ABGR:
openGLImageFormat= GL2.GL_RGBA;
openGLImageType = GL2.GL_UNSIGNED_INT_8_8_8_8; // OK!
openGLImageInternalFormat = GL2.GL_RGBA;
break;
case BufferedImage.TYPE_3BYTE_BGR:
openGLImageFormat= GL2.GL_BGR;
openGLImageType = GL2.GL_UNSIGNED_BYTE;
openGLImageInternalFormat = GL2.GL_RGB;
break;
case BufferedImage.TYPE_BYTE_GRAY:
openGLImageFormat= GL2.GL_LUMINANCE;
openGLImageType = GL2.GL_UNSIGNED_BYTE;
openGLImageInternalFormat = GL2.GL_LUMINANCE;
break;
case BufferedImage.TYPE_CUSTOM:
ColorModel colorModel = image.getColorModel();
ColorSpace colorSpace = colorModel.getColorSpace();
if(colorSpace.getType()==ColorSpace.TYPE_GRAY) {
if(colorModel.hasAlpha()==true) {
openGLImageFormat= GL2.GL_LUMINANCE_ALPHA;
openGLImageType = GL2.GL_UNSIGNED_BYTE;
openGLImageInternalFormat = GL2.GL_LUMINANCE_ALPHA;
}
else {
openGLImageFormat= GL2.GL_LUMINANCE;
openGLImageType = GL2.GL_UNSIGNED_BYTE;
openGLImageInternalFormat = GL2.GL_LUMINANCE;
}
}
else {
errorString = "Unsupported image format."+
"\nURL="+textureBaseURL+textureURL+"\n";
retValue = false;
}
break;
}
}
catch(Throwable t) {
errorString = "Exception during image analyzing."+
"\nURL="+textureBaseURL+textureURL+"\n"+t.getMessage();
retValue = false;
}
if(!errorString.isEmpty()){
StatusPrinter.print("ERROR", errorString, Texture.class);
}
return retValue;
}
示例6: doTest
public void doTest() throws IOException {
/*
* This test verifies that png images with color type RGB or RGBA
* are decoded as buffered image of some standard type.
*
* So we need to be sure that image provided by
* user has required color type - RGB or RGBA
*/
if (!checkImageType()) {
System.out.println("Test IGNORED!");
return;
}
def = reader.read(0);
System.out.println("Default image type: " + def.getType());
if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
throw new RuntimeException("Test FAILED!");
}
raw_type = reader.getRawImageType(0);
ImageReadParam param = reader.getDefaultReadParam();
param.setDestinationType(raw_type);
System.out.println("Reading with raw image type...");
raw = reader.read(0, param);
System.out.println("Type of raw image is " + raw.getType());
compare(def, raw);
Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
while (types.hasNext()) {
ImageTypeSpecifier t = types.next();
System.out.println("Test type: " + t);
param.setDestinationType(t);
BufferedImage img = reader.read(0, param);
System.out.println("Result type: " + img.getType());
compare(def, img);
System.out.println("Done.\n");
}
System.out.println("Test PASSED.");
}
示例7: 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!");
}
}
示例8: createFromBufferedImageType
/**
* Returns an {@code ImageTypeSpecifier} that encodes
* one of the standard {@code BufferedImage} types
* (other than {@code TYPE_CUSTOM}).
*
* @param bufferedImageType an int representing one of the standard
* {@code BufferedImage} types.
*
* @return an {@code ImageTypeSpecifier} with the desired
* characteristics.
*
* @exception IllegalArgumentException if
* {@code bufferedImageType} is not one of the standard
* types, or is equal to {@code TYPE_CUSTOM}.
*
* @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!");
}
}