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


Java ColorSpace.getInstance方法代码示例

本文整理汇总了Java中java.awt.color.ColorSpace.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ColorSpace.getInstance方法的具体用法?Java ColorSpace.getInstance怎么用?Java ColorSpace.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.color.ColorSpace的用法示例。


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

示例1: getColorModel

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
@Override
public ColorModel getColorModel(int transparency) {
    switch (transparency) {
    case Transparency.OPAQUE:
        // REMIND: once the ColorModel spec is changed, this should be
        //         an opaque premultiplied DCM...
        return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    case Transparency.BITMASK:
        return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
    case Transparency.TRANSLUCENT:
        ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        return new DirectColorModel(cs, 32,
                                    0xff0000, 0xff00, 0xff, 0xff000000,
                                    true, DataBuffer.TYPE_INT);
    default:
        return null;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:WGLGraphicsConfig.java

示例2: testConstructor1

import java.awt.color.ColorSpace; //导入方法依赖的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

示例3: main

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public static void main(String[] args) {
    ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);

    byte[] raw_data = pSRGB.getData();

    setRenderingIntent(0x1000000, raw_data);

    ICC_Profile p = ICC_Profile.getInstance(raw_data);

    ICC_ColorSpace cs = new ICC_ColorSpace(p);

    // perfrom test color conversion
    ColorConvertOp op = new ColorConvertOp(cs,
            ColorSpace.getInstance(CS_sRGB), null);
    BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
    BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);

    try {
        op.filter(src.getRaster(), dst.getRaster());
    } catch (CMMException e) {
        throw new RuntimeException("Test failed.", e);
    }
    System.out.println("Test passed.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:InvalidRenderIntentTest.java

示例4: testConstructor2

import java.awt.color.ColorSpace; //导入方法依赖的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

示例5: create3ByteImage

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel colorModel =
        new ComponentColorModel(cs, nBits,
                                false, false,
                                Transparency.OPAQUE,
                                DataBuffer.TYPE_BYTE);
    WritableRaster raster =
        Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
                                       w, h,
                                       w*3, 3,
                                       bOffs, null);
    return new BufferedImage(colorModel, raster, false, null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:BMPSubsamplingTest.java

示例6: Context

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public Context(TestEnvironment env, Result res) {

            graphics = (Graphics2D)env.getGraphics();
            cs = getColorSpace(env);

            // TODO: provide rendering hints
            op_img = new ColorConvertOp(cs, null);
            ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
            op_rst = new ColorConvertOp(sRGB, cs, null);

            int size = env.getIntValue(sizeList);

            ImageContent content = (ImageContent)env.getModifier(contentList);
            ImageType srcType = (ImageType)env.getModifier(sourceType);

            src = createBufferedImage(size, size, content, srcType.type);
            rsrc = src.getRaster();

            ImageType dstType = (ImageType)env.getModifier(destinationType);
            if (dstType == ImageType.COMPATIBLE_DST) {
                dst = op_img.createCompatibleDestImage(src, null);
            } else {
                dst = createBufferedImage(size, size, content, dstType.type);
            }
            // raster always has to be comatible
            rdst = op_rst.createCompatibleDestRaster(rsrc);
        }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:ColorConvertOpTests.java

示例7: getComponents

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
/**
 * Returns a {@code float} array containing the color and alpha
 * components of the {@code Color}, in the
 * {@code ColorSpace} specified by the {@code cspace}
 * parameter.  If {@code compArray} is {@code null}, an
 * array with length equal to the number of components in
 * {@code cspace} plus one is created for the return value.
 * Otherwise, {@code compArray} must have at least this
 * length, and it is filled in with the components and returned.
 * @param cspace a specified {@code ColorSpace}
 * @param compArray an array that this method fills with the
 *          color and alpha components of this {@code Color} in
 *          the specified {@code ColorSpace} and returns
 * @return the color and alpha components in a {@code float}
 *          array.
 */
public float[] getComponents(ColorSpace cspace, float[] compArray) {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    float f[];
    if (fvalue == null) {
        f = new float[3];
        f[0] = ((float)getRed())/255f;
        f[1] = ((float)getGreen())/255f;
        f[2] = ((float)getBlue())/255f;
    } else {
        f = fvalue;
    }
    float tmp[] = cs.toCIEXYZ(f);
    float tmpout[] = cspace.fromCIEXYZ(tmp);
    if (compArray == null) {
        compArray = new float[tmpout.length + 1];
    }
    for (int i = 0 ; i < tmpout.length ; i++) {
        compArray[i] = tmpout[i];
    }
    if (fvalue == null) {
        compArray[tmpout.length] = ((float)getAlpha())/255f;
    } else {
        compArray[tmpout.length] = falpha;
    }
    return compArray;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:Color.java

示例8: main

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    ColorConvertOp op = new ColorConvertOp(cs, null);
    // create source image filled with an opaque color
    BufferedImage src = createSrc();
    int srcAlpha = getAlpha(src);

    System.out.printf("Src alpha: 0x%02x\n", srcAlpha);

    // create clear (transparent black) destination image
    BufferedImage dst = createDst();
    int dstAlpha = getAlpha(dst);
    System.out.printf("Dst alpha: 0x%02x\n", dstAlpha);


    dst = op.filter(src, dst);
    dstAlpha = getAlpha(dst);
    // we expect that destination image is opaque
    // i.e. alpha is transferred from source to
    // the destination
    System.out.printf("Result alpha: 0x%02x\n", dstAlpha);

    if (srcAlpha != dstAlpha) {
        throw new RuntimeException("Test failed!");
    }
    System.out.println("Test passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:AlphaTest.java

示例9: getColorSpace

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
/**
 * Returns the <code>ColorSpace</code> of this <code>Color</code>.
 * @return this <code>Color</code> object's <code>ColorSpace</code>.
 */
public ColorSpace getColorSpace() {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    return cs;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:Color.java

示例10: createABGRCCM

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public static ComponentColorModel createABGRCCM() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8, 8};
    int[] bOffs = {3, 2, 1, 0};
    return new ComponentColorModel(cs, nBits, true, true,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:X11GraphicsConfig.java

示例11: SimpleCMYKColorSpace

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
private SimpleCMYKColorSpace() {
    super(TYPE_CMYK, 4);
    csRGB = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:SimpleCMYKColorSpace.java

示例12: createDCM32

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public static DirectColorModel createDCM32(int rMask, int gMask, int bMask,
                                           int aMask, boolean aPre) {
    return new DirectColorModel(
        ColorSpace.getInstance(ColorSpace.CS_sRGB),
        32, rMask, gMask, bMask, aMask, aPre, DataBuffer.TYPE_INT);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:X11GraphicsConfig.java

示例13: Grayscale

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
public Grayscale(int bits,
                 int dataType,
                 boolean isSigned,
                 boolean hasAlpha,
                 boolean isAlphaPremultiplied)
{
    if (bits != 1 && bits != 2 && bits != 4 &&
        bits != 8 && bits != 16)
    {
        throw new IllegalArgumentException("Bad value for bits!");
    }
    if (dataType != DataBuffer.TYPE_BYTE &&
        dataType != DataBuffer.TYPE_SHORT &&
        dataType != DataBuffer.TYPE_USHORT)
    {
        throw new IllegalArgumentException
            ("Bad value for dataType!");
    }
    if (bits > 8 && dataType == DataBuffer.TYPE_BYTE) {
        throw new IllegalArgumentException
            ("Too many bits for dataType!");
    }

    this.bits = bits;
    this.dataType = dataType;
    this.isSigned = isSigned;
    this.hasAlpha = hasAlpha;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);

    if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
        (bits == 16 &&
         (dataType == DataBuffer.TYPE_SHORT ||
          dataType == DataBuffer.TYPE_USHORT))) {
        // Use component color model & sample model

        int numBands = hasAlpha ? 2 : 1;
        int transparency =
            hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;


        int[] nBits = new int[numBands];
        nBits[0] = bits;
        if (numBands == 2) {
            nBits[1] = bits;
        }
        this.colorModel =
            new ComponentColorModel(colorSpace,
                                    nBits,
                                    hasAlpha,
                                    isAlphaPremultiplied,
                                    transparency,
                                    dataType);

        int[] bandOffsets = new int[numBands];
        bandOffsets[0] = 0;
        if (numBands == 2) {
            bandOffsets[1] = 1;
        }

        int w = 1;
        int h = 1;
        this.sampleModel =
            new PixelInterleavedSampleModel(dataType,
                                            w, h,
                                            numBands, w*numBands,
                                            bandOffsets);
    } else {
        int numEntries = 1 << bits;
        byte[] arr = new byte[numEntries];
        for (int i = 0; i < numEntries; i++) {
            arr[i] = (byte)(i*255/(numEntries - 1));
        }
        this.colorModel =
            new IndexColorModel(bits, numEntries, arr, arr, arr);

        this.sampleModel =
            new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:82,代码来源:ImageTypeSpecifier.java

示例14: imageGray

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
/**
 * 图片黑白化操作(文件物理存盘,可自定义格式)
 * 
 * @param bufferedImage
 *                 处理的图片对象
 * @param format
 *                 图片格式
 * @param destPath
 *                 目标文件地址
 * @throws Exception 
 * 
 */
public static void imageGray(String imgPath,String format, String destPath)throws Exception{
    try {
         BufferedImage bufferedImage = ImageIO.read(new File(imgPath));
         ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);            
         ColorConvertOp op = new ColorConvertOp(cs, null);  
         bufferedImage = op.filter(bufferedImage, null);
         ImageIO.write(bufferedImage, format , new File(destPath));
    } catch (Exception e) {
        throw new RuntimeException("图片灰白化异常");
    }
}
 
开发者ID:onsoul,项目名称:os,代码行数:24,代码来源:ImageUtil.java

示例15: IndexColorModel

import java.awt.color.ColorSpace; //导入方法依赖的package包/类
/**
 * Constructs an <code>IndexColorModel</code> from the given arrays
 * of red, green, and blue components.  Pixels described by this color
 * model all have alpha components of 255 unnormalized
 * (1.0&nbsp;normalized), which means they are fully opaque, except
 * for the indicated pixel to be made transparent.  All of the arrays
 * specifying the color components must have at least the specified
 * number of entries.
 * The <code>ColorSpace</code> is the default sRGB space.
 * The transparency value may be <code>Transparency.OPAQUE</code> or
 * <code>Transparency.BITMASK</code> depending on the arguments, as
 * specified in the <a href="#transparency">class description</a> above.
 * The transfer type is the smallest of <code>DataBuffer.TYPE_BYTE</code>
 * or <code>DataBuffer.TYPE_USHORT</code> that can hold a
 * single pixel.
 * @param bits      the number of bits each pixel occupies
 * @param size      the size of the color component arrays
 * @param r         the array of red color components
 * @param g         the array of green color components
 * @param b         the array of blue color components
 * @param trans     the index of the transparent pixel
 * @throws IllegalArgumentException if <code>bits</code> is less than
 *          1 or greater than 16
 * @throws IllegalArgumentException if <code>size</code> is less than
 *          1
 */
public IndexColorModel(int bits, int size,
                       byte r[], byte g[], byte b[], int trans) {
    super(bits, opaqueBits,
          ColorSpace.getInstance(ColorSpace.CS_sRGB),
          false, false, OPAQUE,
          ColorModel.getDefaultTransferType(bits));
    if (bits < 1 || bits > 16) {
        throw new IllegalArgumentException("Number of bits must be between"
                                           +" 1 and 16.");
    }
    setRGBs(size, r, g, b, null);
    setTransparentPixel(trans);
    calculatePixelMask();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:IndexColorModel.java


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