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


Java BufferedImage.getData方法代码示例

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


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

示例1: getGUISnapshots

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
static Snapshot[] getGUISnapshots() {
    List snapshots = new ArrayList();   //System.err.println("gGUI: thread = "+Thread.currentThread());
    Window[] windows = Window.getWindows(); //System.err.println("gGUI: windows = "+windows.length);
    for (int wi = 0; wi < windows.length; wi++) {
        Window w = windows[wi]; //System.err.println("gGUI: w["+wi+"] = "+w+", is visible = "+w.isVisible());
        if (!w.isVisible()) {
            continue;
        }
        Dimension d = w.getSize();  //System.err.println("gGUI:  size = "+d);
        if (d.width == 0 || d.height == 0) {
            continue;
        }
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bi.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
        w.paint(g);
        Raster raster = bi.getData();
        Object data = raster.getDataElements(0, 0, d.width, d.height, null);
        int[] dataArr;  //System.err.println("gGUI: data = "+data);
        if (data instanceof int[]) {
            dataArr = (int[]) data;
        } else {
            continue;
        }
        String title = null;
        if (w instanceof Frame) {
            title = ((Frame) w).getTitle();
        } else if (w instanceof Dialog) {
            title = ((Dialog) w).getTitle();
        }   //System.err.println("gGUI: title = "+title);
        snapshots.add(new Snapshot(w, title, d.width, d.height, dataArr));
    }
    Snapshot[] snapshotArr = (Snapshot[]) snapshots.toArray(new Snapshot[] {});
    lastGUISnapshots = snapshotArr;
    return snapshotArr;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:RemoteAWTService.java

示例2: gethISTNode

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private IIOMetadataNode gethISTNode(BufferedImage bi) {
    IndexColorModel icm = (IndexColorModel)bi.getColorModel();
    int mapSize = icm.getMapSize();

    int[] hist = new int[mapSize];
    Arrays.fill(hist, 0);

    Raster r = bi.getData();
    for (int y = 0; y < bi.getHeight(); y++) {
        for (int x = 0; x < bi.getWidth(); x++) {
            int s = r.getSample(x, y, 0);
            hist[s] ++;
        }
    }

    IIOMetadataNode hIST = new IIOMetadataNode("hIST");
    for (int i = 0; i < hist.length; i++) {
        IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
        n.setAttribute("index", "" + i);
        n.setAttribute("value", "" + hist[i]);
        hIST.appendChild(n);
    }

    return hIST;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:ShortHistogramTest.java

示例3: getRasterDataMask

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * rasterize the mask clipped with the Rectangle scaled back to full size with an offset onto a BufferedImage
 */
public int[] getRasterDataMask(int x,int y,int w,int h,  int offsetX, int offsetY, double scalingFactor) {
	Rectangle rect=new Rectangle(x,y,w,h);
    //BufferedImage bi = this.rasterize(rect, offsetX, offsetY, scalingFactor);
    BufferedImage bi = this.rasterize(rect, offsetX, offsetY,scalingFactor);
    //this.saveRaster(bi, new File("E:/tmp/raster.bmp"));
    Raster rastermask=bi.getData();
	int[] maskdata=rastermask.getSamples(0, 0, rastermask.getWidth(), rastermask.getHeight(),0, (int[])null);
	return maskdata;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:13,代码来源:MaskGeometries.java

示例4: getImageFromArray

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static Image getImageFromArray(int[] pixels, int width, int height) {
    BufferedImage image = new BufferedImage(width, height+1, BufferedImage.TYPE_INT_ARGB);
    WritableRaster raster = (WritableRaster) image.getData();
    System.out.println("px;" + pixels.length + " as opposed to " + (height*width));
    raster.setPixels(0,0,width,height-1,pixels);
    
    return image;
}
 
开发者ID:fossasia,项目名称:zooracle,代码行数:9,代码来源:ImgUtils.java

示例5: imageToMat

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static double[][] imageToMat(BufferedImage img) {
    int width = img.getWidth();
    int height = img.getHeight();
    double[][] imgArr = new double[width][height];
    Raster raster = img.getData();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            imgArr[i][j] = raster.getSample(i, j, 0);
        }
    }
    return imgArr;
}
 
开发者ID:emara-geek,项目名称:arabic-characters-recognition,代码行数:13,代码来源:TestModel.java

示例6: readRaster

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public Raster readRaster(int imageIndex,
                         ImageReadParam param) throws IOException {
    BufferedImage bi = read(imageIndex, param);
    return bi.getData();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:WBMPImageReader.java

示例7: testFillDefaultAt

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static void testFillDefaultAt() {
    final int width = 400;
    final int height = 400;

    final BufferedImage image = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        final Path2D.Double path = new Path2D.Double();
        path.moveTo(100, 100);

        for (int i = 0; i < 20000; i++) {
            path.lineTo(110 + 0.01 * i, 110);
            path.lineTo(111 + 0.01 * i, 100);
        }

        path.lineTo(NaN, 200);
        path.lineTo(200, 200);
        path.lineTo(200, NaN);
        path.lineTo(300, 300);
        path.lineTo(NaN, NaN);
        path.lineTo(100, 200);
        path.closePath();

        final Path2D.Double path2 = new Path2D.Double();
        path2.moveTo(0, 0);
        path2.lineTo(100, height);
        path2.lineTo(0, 200);
        path2.closePath();

        g2d.setColor(Color.BLUE);
        g2d.fill(path);
        g2d.setColor(Color.GREEN);
        g2d.fill(path2);

        g2d.setColor(Color.BLACK);
        g2d.draw(path);
        g2d.draw(path2);

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashNaNTest-fill.png");
                System.out.println("Writing file: "
                                   + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }

        // Check image on few pixels:
        final Raster raster = image.getData();

        checkPixel(raster, 200, 195, Color.BLUE.getRGB());
        checkPixel(raster, 105, 195, Color.BLUE.getRGB());
        checkPixel(raster, 286, 290, Color.BLUE.getRGB());

        checkPixel(raster, 108, 105, Color.WHITE.getRGB());
        checkPixel(raster, 205, 200, Color.WHITE.getRGB());

        checkPixel(raster, 5, 200, Color.GREEN.getRGB());

    } finally {
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:75,代码来源:CrashNaNTest.java

示例8: testDrawComplexAt

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static void testDrawComplexAt() {
    final int width = 400;
    final int height = 400;

    final BufferedImage image = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                             RenderingHints.VALUE_STROKE_PURE);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        final Path2D.Double path = new Path2D.Double();
        path.moveTo(100, 100);

        for (int i = 0; i < 20000; i++) {
            path.lineTo(110 + 0.01 * i, 110);
            path.lineTo(111 + 0.01 * i, 100);
        }

        path.lineTo(NaN, 200);
        path.lineTo(200, 200);
        path.lineTo(200, NaN);
        path.lineTo(300, 300);
        path.lineTo(NaN, NaN);
        path.lineTo(100, 200);
        path.closePath();

        final Path2D.Double path2 = new Path2D.Double();
        path2.moveTo(0, 0);
        path2.lineTo(100, height);
        path2.lineTo(0, 200);
        path2.closePath();

        // Define an non-uniform transform:
        g2d.scale(0.5, 1.0);
        g2d.rotate(Math.PI / 31);

        g2d.setColor(Color.BLACK);
        g2d.draw(path);
        g2d.draw(path2);

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashNaNTest-draw.png");
                System.out.println("Writing file: "
                                   + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }

        // Check image on few pixels:
        final Raster raster = image.getData();

        checkPixelNotWhite(raster, 40, 210);
        checkPixelNotWhite(raster, 44, 110);
        checkPixelNotWhite(raster, 60, 120);
        checkPixelNotWhite(raster, 89, 219);
        checkPixelNotWhite(raster, 28, 399);
        checkPixelNotWhite(raster, 134, 329);

    } finally {
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:74,代码来源:CrashNaNTest.java

示例9: testPathClosed

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
private static void testPathClosed() {
    final int width = 100;
    final int height = 100;

    final BufferedImage image = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        final Path2D.Double path = new Path2D.Double();
        path.moveTo(40, 40);
        path.lineTo(0,   0);
        path.lineTo(80, 0);
        path.closePath();
        path.lineTo(80, 80);
        path.lineTo(0, 80);
        path.closePath();

        g2d.setColor(Color.BLUE);
        g2d.fill(path);

        g2d.setColor(Color.BLACK);
        g2d.draw(path);

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashNaNTest-path-closed.png");
                System.out.println("Writing file: "
                                   + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }

        // Check image on few pixels:
        final Raster raster = image.getData();

        checkPixel(raster, 10, 05, Color.BLUE.getRGB());
        checkPixel(raster, 70, 05, Color.BLUE.getRGB());
        checkPixel(raster, 40, 35, Color.BLUE.getRGB());

        checkPixel(raster, 10, 75, Color.BLUE.getRGB());
        checkPixel(raster, 70, 75, Color.BLUE.getRGB());
        checkPixel(raster, 40, 45, Color.BLUE.getRGB());

    } finally {
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:58,代码来源:CrashNaNTest.java


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