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


Java Raster.getPixels方法代码示例

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


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

示例1: grabPixels

import java.awt.image.Raster; //导入方法依赖的package包/类
/**
 * Put the scanline y of the source ROI view Raster into the
 * 1-line Raster for writing.  This handles ROI and band
 * rearrangements, and expands indexed images.  Subsampling is
 * done in the native code.
 * This is called by the native code.
 */
private void grabPixels(int y) {

    Raster sourceLine = null;
    if (indexed) {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        new int [] {0});
        // If the image has BITMASK transparency, we need to make sure
        // it gets converted to 32-bit ARGB, because the JPEG encoder
        // relies upon the full 8-bit alpha channel.
        boolean forceARGB =
            (indexCM.getTransparency() != Transparency.OPAQUE);
        BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine,
                                                          forceARGB);
        sourceLine = temp.getRaster();
    } else {
        sourceLine = srcRas.createChild(sourceXOffset,
                                        sourceYOffset+y,
                                        sourceWidth, 1,
                                        0, 0,
                                        srcBands);
    }
    if (convertTosRGB) {
        if (debug) {
            System.out.println("Converting to sRGB");
        }
        // The first time through, converted is null, so
        // a new raster is allocated.  It is then reused
        // on subsequent lines.
        converted = convertOp.filter(sourceLine, converted);
        sourceLine = converted;
    }
    if (isAlphaPremultiplied) {
        WritableRaster wr = sourceLine.createCompatibleWritableRaster();
        int[] data = null;
        data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                                    sourceLine.getWidth(), sourceLine.getHeight(),
                                    data);
        wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(),
                     sourceLine.getWidth(), sourceLine.getHeight(),
                     data);
        srcCM.coerceData(wr, false);
        sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(),
                                    wr.getWidth(), wr.getHeight(),
                                    0, 0,
                                    srcBands);
    }
    raster.setRect(sourceLine);
    if ((y > 7) && (y%8 == 0)) {  // Every 8 scanlines
        cbLock.lock();
        try {
            processImageProgress((float) y / (float) sourceHeight * 100.0F);
        } finally {
            cbLock.unlock();
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:67,代码来源:JPEGImageWriter.java

示例2: apply

import java.awt.image.Raster; //导入方法依赖的package包/类
@Override
public void apply(Diagram d) {
    boolean logarithmic = mode.equalsIgnoreCase(LOGARITHMIC);
    if (!logarithmic && !mode.equalsIgnoreCase(LINEAR)) {
        throw new RuntimeException("Unknown mode: " + mode);
    }

    Rectangle bounds = new Rectangle(shadeCount, 1);
    LinearGradientPaint lgp = new LinearGradientPaint(bounds.x, bounds.y, bounds.width, bounds.y, fractions, colors);
    PaintContext context = lgp.createContext(null, bounds, bounds.getBounds2D(), AffineTransform.getTranslateInstance(0, 0), new RenderingHints(null));
    Raster raster = context.getRaster(bounds.x, bounds.y, bounds.width, bounds.height);
    int[] rgb = raster.getPixels(bounds.x, bounds.y, bounds.width, bounds.height, (int[]) null);
    Color[] shades = new Color[rgb.length / 3];
    for (int i = 0; i < shades.length; ++i) {
        shades[i] = new Color(rgb[i * 3], rgb[i * 3 + 1], rgb[i * 3 + 2]);
    }

    List<Figure> figures = d.getFigures();
    for (Figure f : figures) {
        String property = f.getProperties().get(propertyName);
        if (property != null) {
            try {
                float value = Float.parseFloat(property);

                Color nodeColor;
                if (value <= minValue) {
                    nodeColor = colors[0];
                } else if (value >= maxValue) {
                    nodeColor = colors[colors.length - 1];
                } else {
                    double normalized = value - minValue;
                    double interval = maxValue - minValue;
                    int index;
                    // Use Math.ceil() to make values above zero distinguishable from zero
                    if (logarithmic) {
                        index = (int) Math.ceil(shades.length * Math.log(1 + normalized) / Math.log(1 + interval));
                    } else {
                        index = (int) Math.ceil(shades.length * normalized / interval);
                    }
                    nodeColor = shades[index];
                }
                f.setColor(nodeColor);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:49,代码来源:GradientColorFilter.java


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