当前位置: 首页>>代码示例>>Java>>正文


Java ComponentColorModel类代码示例

本文整理汇总了Java中java.awt.image.ComponentColorModel的典型用法代码示例。如果您正苦于以下问题:Java ComponentColorModel类的具体用法?Java ComponentColorModel怎么用?Java ComponentColorModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ComponentColorModel类属于java.awt.image包,在下文中一共展示了ComponentColorModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createComponentCM

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:ImageTypeSpecifier.java

示例2: createFloatBufferedImage

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
BufferedImage createFloatBufferedImage(int w, int h, int bands) {
    // Define dimensions and layout of the image
    //int bands = 4; // 4 bands for ARGB, 3 for RGB etc
    int[] bandOffsets = {0, 1, 2, 3}; // length == bands, 0 == R, 1 == G, 2 == B and 3 == A

    // Create a TYPE_FLOAT sample model (specifying how the pixels are stored)
    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT, w, h, bands, w  * bands, bandOffsets);
    // ...and data buffer (where the pixels are stored)
    DataBuffer buffer = new DataBufferFloat(w * h * bands);

    // Wrap it in a writable raster
    WritableRaster raster = Raster.createWritableRaster(sampleModel, buffer, null);

    // Create a color model compatible with this sample model/raster (TYPE_FLOAT)
    // Note that the number of bands must equal the number of color components in the 
    // color space (3 for RGB) + 1 extra band if the color model contains alpha 
    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel = new ComponentColorModel(colorSpace, true, false, Transparency.TRANSLUCENT, DataBuffer.TYPE_FLOAT);

    // And finally create an image with this raster
    return new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);
}
 
开发者ID:iapafoto,项目名称:DicomViewer,代码行数:23,代码来源:OpenCLWithJOCL.java

示例3: createComponentCM

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
/**
 * Create a {@code ComponentColorModel} for use in creating
 * an {@code ImageTypeSpecifier}.
 */
// This code was inspired by the method of the same name in
// javax.imageio.ImageTypeSpecifier
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int[] bitsPerSample,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    return new ComponentColorModel(colorSpace,
                                   bitsPerSample,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:TIFFDecompressor.java

示例4: verifyEquals

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
private static void verifyEquals(ComponentColorModel m1,
                                 ComponentColorModel m2) {
    if (m1.equals(null)) {
        throw new RuntimeException("equals(null) returns true");
    }
    if (!(m1.equals(m2))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (!(m2.equals(m1))) {
        throw new RuntimeException("equals() method is not working"
                + " properly");
    }
    if (m1.hashCode() != m2.hashCode()) {
        throw new RuntimeException("HashCode is not same for same"
                + " ComponentColorModels");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ComponentColorModelEqualsTest.java

示例5: testConstructor1

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
private static void testConstructor1() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  int[] bits,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                new int[] {8, 8, 8},
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ComponentColorModelEqualsTest.java

示例6: testConstructor2

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
private static void testConstructor2() {
    /*
     * verify equality with constructor
     * ComponentColorModel(ColorSpace colorSpace,
     *                  boolean hasAlpha,
     *                  boolean isAlphaPremultiplied,
     *                  int transparency,
     *                  int transferType)
     */
    ComponentColorModel model1 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    ComponentColorModel model2 =
        new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                false,
                                false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    verifyEquals(model1, model2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ComponentColorModelEqualsTest.java

示例7: createComponentImage

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
protected static BufferedImage createComponentImage(int w, int h,
                                                    ComponentColorModel cm)
{
    WritableRaster wr = cm.createCompatibleWritableRaster(w, h);

    BufferedImage img = new BufferedImage(cm, wr, false, null);
    Graphics2D g = img.createGraphics();
    int width = w / 8;
    Color[] colors = new Color[8];
    colors[0] = Color.red;
    colors[1] = Color.green;
    colors[2] = Color.blue;
    colors[3] = Color.white;
    colors[4] = Color.black;
    colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
    colors[6] = Color.yellow;
    colors[7] = Color.cyan;

    for (int i = 0; i < 8; i++) {
        g.setColor(colors[i]);
        g.fillRect(i * width, 0, width, h);
    }
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:IndexingTest.java

示例8: createComponentCM

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
/**
 * Create a {@code ComponentColorModel} for use in creating
 * an {@code ImageTypeSpecifier}.
 */
// This code was copied from javax.imageio.ImageTypeSpecifier.
static ColorModel createComponentCM(ColorSpace colorSpace,
                                    int numBands,
                                    int dataType,
                                    boolean hasAlpha,
                                    boolean isAlphaPremultiplied) {
    int transparency =
        hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;

    int[] numBits = new int[numBands];
    int bits = DataBuffer.getDataTypeSize(dataType);

    for (int i = 0; i < numBands; i++) {
        numBits[i] = bits;
    }

    return new ComponentColorModel(colorSpace,
                                   numBits,
                                   hasAlpha,
                                   isAlphaPremultiplied,
                                   transparency,
                                   dataType);
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:28,代码来源:TIFFDecompressor.java

示例9: TextureLoader

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
/**
 * Create a new texture loader based on the game panel
 */
public TextureLoader() {
    glAlphaColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,8},
                                        true,
                                        false,
                                        ComponentColorModel.TRANSLUCENT,
                                        DataBuffer.TYPE_BYTE);

    glColorModel = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB),
                                        new int[] {8,8,8,0},
                                        false,
                                        false,
                                        ComponentColorModel.OPAQUE,
                                        DataBuffer.TYPE_BYTE);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:TextureLoader.java

示例10: FilterAsAlphaRed

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
/**
 * Construct an alpah channel from the given src, according to
 * the SVG masking rules.
 *
 * @param src The image to convert to an alpha channel (mask image)
 */
public FilterAsAlphaRed(CachableRed src) {
    super(new Any2LumRed(src),src.getBounds(), 
          new ComponentColorModel
              (ColorSpace.getInstance(ColorSpace.CS_GRAY),
               new int [] {8}, false, false,
               Transparency.OPAQUE, 
               DataBuffer.TYPE_BYTE),
          new PixelInterleavedSampleModel
              (DataBuffer.TYPE_BYTE, 
               src.getSampleModel().getWidth(),
               src.getSampleModel().getHeight(),
               1, src.getSampleModel().getWidth(),
               new int [] { 0 }),
          src.getTileGridXOffset(),
          src.getTileGridYOffset(),
          null);

    props.put(ColorSpaceHintKey.PROPERTY_COLORSPACE,
              ColorSpaceHintKey.VALUE_COLORSPACE_ALPHA);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:27,代码来源:FilterAsAlphaRed.java

示例11: construct

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
public static CachableRed construct(CachableRed src, ColorModel cm) {
    ColorModel srcCM = src.getColorModel();
    if ((cm.hasAlpha() != srcCM.hasAlpha()) ||
        (cm.isAlphaPremultiplied() != srcCM.isAlphaPremultiplied()))
        return new FormatRed(src, cm);

    if (cm.getNumComponents() != srcCM.getNumComponents())
        throw new IllegalArgumentException
            ("Incompatible ColorModel given");


    if ((srcCM instanceof ComponentColorModel) &&
        (cm    instanceof ComponentColorModel))
        return src;

    if ((srcCM instanceof DirectColorModel) &&
        (cm    instanceof DirectColorModel))
        return src;

    return new FormatRed(src, cm);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:22,代码来源:FormatRed.java

示例12: fixColorModel

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
public static ColorModel fixColorModel(CachableRed src) {
    ColorModel  cm = src.getColorModel();

    if (cm.hasAlpha())
        return cm;

    int b = src.getSampleModel().getNumBands()+1;
    int [] bits = new int[b];
    for (int i=0; i < b; i++)
        bits[i] = 8;

    ColorSpace cs = cm.getColorSpace();

    return new ComponentColorModel(cs, bits, true, false,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:18,代码来源:MultiplyAlphaRed.java

示例13: getSnapshot

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
@Override
public BufferedImage getSnapshot()
{
  // TODO: Support non-24-bit resolutions.
  int w = pixmap.width;
  int h = pixmap.height;
  ZPixmap zpixmap = (ZPixmap) pixmap.image(0, 0, w, h, 0xffffffff,
                                           Image.Format.ZPIXMAP);
  DataBuffer buffer = new ZPixmapDataBuffer(zpixmap);
  SampleModel sm = new ComponentSampleModel(DataBuffer.TYPE_BYTE, w, h, 4,
                                            w * 4,
                                            new int[]{0, 1, 2, 3 });
  ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
  ColorModel cm = new ComponentColorModel(cs, true, false,
                                          Transparency.OPAQUE,
                                          DataBuffer.TYPE_BYTE);
  WritableRaster raster = Raster.createWritableRaster(sm, buffer,
                                                      new Point(0, 0));
  return new BufferedImage(cm, raster, false, null);
}
 
开发者ID:vilie,项目名称:javify,代码行数:21,代码来源:PixmapVolatileImage.java

示例14: toImage

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
public static BufferedImage toImage(int w, int h, byte[] data) {
	DataBuffer buffer = new DataBufferByte(data, w * h);

	int pixelStride = 3; // assuming r, g, b, r, g, b,...
	int scanlineStride = 3 * w; // no extra padding
	int[] bandOffsets = { 0, 1, 2 }; // r, g, b
	WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h, scanlineStride, pixelStride, bandOffsets, null);

	ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
	boolean hasAlpha = false;
	boolean isAlphaPremultiplied = false;
	int transparency = Transparency.OPAQUE;
	int transferType = DataBuffer.TYPE_BYTE;
	ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha, isAlphaPremultiplied, transparency, transferType);

	return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:18,代码来源:Convert.java

示例15: pixelsToImage

import java.awt.image.ComponentColorModel; //导入依赖的package包/类
public static BufferedImage pixelsToImage(byte[] data, int w, int h) {
	DataBuffer buffer = new DataBufferByte(data, w * h);

	int pixelStride = 1; // assuming r, g, b,
							// skip, r, g, b,
							// skip...
	int scanlineStride = w; // no extra
							// padding
	int[] bandOffsets = { 0 }; // r, g, b
	WritableRaster raster = Raster.createInterleavedRaster(buffer, w, h,
			scanlineStride, pixelStride, bandOffsets, null);

	ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
	boolean hasAlpha = false;
	boolean isAlphaPremultiplied = false;
	int transparency = Transparency.OPAQUE;
	int transferType = DataBuffer.TYPE_BYTE;
	ColorModel colorModel = new ComponentColorModel(colorSpace, hasAlpha,
			isAlphaPremultiplied, transparency, transferType);

	return new BufferedImage(colorModel, raster, isAlphaPremultiplied, null);
}
 
开发者ID:TOMIGalway,项目名称:cmoct-sourcecode,代码行数:23,代码来源:ImageOperations.java


注:本文中的java.awt.image.ComponentColorModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。