Java Code Examples for java.awt.image.BufferedImage.getWidth()

The following are Jave code examples for showing how to use getWidth() of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GIFKR   File: ConvolutionFilter.java   View Source Code Vote up 6 votes
@Override
public final BufferedImage apply(BufferedImage img) {
	
	float[][] matrix = getMatrix();
	float[] data = getKernelData(matrix);
	if(normalize)
		normalize(data); 
	scale(data);
	if(isZero(data))
		return new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
	
	Kernel k = new Kernel(matrix[0].length, matrix.length, data);
	ConvolveOp op = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, null);
	
	BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
	img2.getGraphics().drawImage(img, 0, 0, null);
	
	return op.filter(img2, null);
}
 
Example 2
Project: Pixie   File: CropWindow.java   View Source Code Vote up 6 votes
/**
 * Load the segmented result of the crop image to a visualisation panel.
 */
private void loadCropResult(BufferedImage cropResult) {
    // remove the old image if it exists
    if (dPCropResult != null) {
        this.remove(dPCropResult);
        jPCropResult.remove(dPCropResult);
    }

    // load the viewer of the result
    dPCropResult = new ResultPanel(cropResult, new Dimension(cropResult.getWidth(), cropResult.getHeight()), cropWindowConfig.getObjectColor());
    dPCropResult.updateResultImg();
    dPCropResult.setBackground(new java.awt.Color(255, 255, 255));

    jPCropResult.add(dPCropResult);

    this.validate();
    this.repaint();

}
 
Example 3
Project: GIFKR   File: LinePixelSort.java   View Source Code Vote up 6 votes
@Override
protected BufferedImage apply(BufferedImage img) {

	float flength = 1 + (img.getWidth()-1) * threshold;
	int length = Math.round(flength);

	for (int y = 0, x = 0; y < img.getHeight(); y++) {
		for(x = 0; x < img.getWidth() && ((img.getRGB(x, y) & 0xFF000000) == 0); x++);

		int firstEnd = Math.round(flength*(x/length +1)) -1;

		line(img, x, Math.min(img.getWidth()-1, firstEnd), y);
		x = firstEnd+1;

		for(float fx = x; x < img.getWidth()-length && ((img.getRGB(x + length, y) & 0xFF000000) != 0); fx += flength, x = Math.round(fx))
			line(img, x, Math.round(fx + flength)-1, y);

		int end = x;
		for(; end < img.getWidth() - 1 && ((img.getRGB(end, y) & 0xFF000000) != 0); end++);
		line(img, x, end, y);
	}
	return img;
}
 
Example 4
Project: geomapapp   File: GeoMapAppToWorldWindTiler.java   View Source Code Vote up 6 votes
private static BufferedImage resizeImage(BufferedImage sample, double sampleMinLat, double sampleMaxLat, double tileMinLat, double tileMaxLat) {
	BufferedImage img = new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_3BYTE_BGR);
	double tileScale = TILE_SIZE / (tileMinLat - tileMaxLat);
	
	// s for source; d for destination; all measurements in pixels
	int sx1 = 0;
	int sy1 = 0;
	int sx2 = sample.getWidth();
	int sy2 = sample.getHeight();
	
	int dx1 = 0;
	int dy1 = (int) ((sampleMaxLat - tileMaxLat) * tileScale);
	int dx2 = TILE_SIZE;
	int dy2 = (int) ((sampleMinLat - tileMaxLat) * tileScale);
	
	img.createGraphics().drawImage(sample, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
	
	return img;
}
 
Example 5
Project: DecompiledMinecraft   File: TextureUtil.java   View Source Code Vote up 6 votes
private static void uploadTextureImageSubImpl(BufferedImage p_110993_0_, int p_110993_1_, int p_110993_2_, boolean p_110993_3_, boolean p_110993_4_)
{
    int i = p_110993_0_.getWidth();
    int j = p_110993_0_.getHeight();
    int k = 4194304 / i;
    int[] aint = new int[k * i];
    setTextureBlurred(p_110993_3_);
    setTextureClamped(p_110993_4_);

    for (int l = 0; l < i * j; l += i * k)
    {
        int i1 = l / i;
        int j1 = Math.min(k, j - i1);
        int k1 = i * j1;
        p_110993_0_.getRGB(0, i1, i, j1, aint, 0, i);
        copyToBuffer(aint, k1);
        GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, p_110993_1_, p_110993_2_ + i1, i, j1, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, (IntBuffer)dataBuffer);
    }
}
 
Example 6
Project: jmonet   File: AbstractSelectionTool.java   View Source Code Vote up 6 votes
/**
 * Creates a new image in which every pixel not within the given shape has been changed to fully transparent.
 *
 * @param image The image to mask
 * @param mask  The shape bounding the subimage to keep
 * @return A BufferedImage in which every pixel not within the selection has been made fully transparent
 */
private BufferedImage maskSelection(BufferedImage image, Shape mask) {
    BufferedImage subimage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);

    int clearPixel = new Color(0, 0, 0, 0).getRGB();

    for (int y = 0; y < image.getRaster().getHeight(); y++) {
        for (int x = 0; x < image.getRaster().getWidth(); x++) {
            if (x > image.getWidth() || y > image.getHeight()) continue;

            if (mask.contains(x, y)) {
                subimage.setRGB(x, y, image.getRGB(x, y));
            } else {
                subimage.setRGB(x, y, clearPixel);
            }
        }
    }

    return subimage;
}
 
Example 7
Project: openjdk-jdk10   File: UpdatePopupMenu.java   View Source Code Vote up 6 votes
private Image createSystemTrayIconImage() {
    final BufferedImage trayImage = new BufferedImage(
            imageSize,
            imageSize,
            BufferedImage.TYPE_INT_ARGB);

    final Graphics2D imageGraphics = (Graphics2D) trayImage.getGraphics();

    imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    imageGraphics.setColor(new Color(255, 255, 255, 0));
    imageGraphics.fillRect(0, 0, trayImage.getWidth(),
            trayImage.getHeight());

    imageGraphics.setColor(Color.green);

    int imageWidth = trayImage.getWidth() - 2 * imageInset;
    int imageHeight = trayImage.getHeight() - 2 * imageInset;

    imageGraphics.fillOval(imageInset, imageInset, imageWidth, imageHeight);
    imageGraphics.setColor(Color.darkGray);
    imageGraphics.drawOval(imageInset, imageInset, imageWidth, imageHeight);

    return trayImage;
}
 
Example 8
Project: jdk8u-jdk   File: bug8016833.java   View Source Code Vote up 6 votes
Rectangle getPixelsOutline(BufferedImage img) {
    int x1 = 0;
    while (x1 < img.getWidth() && isLineEmpty(img, x1, false)) {
        x1++;
    }
    int x2 = img.getWidth() - 1;
    while (x2 >= 0 && isLineEmpty(img, x2, false)) {
        x2--;
    }
    int y1 = 0;
    while (y1 < img.getHeight() && isLineEmpty(img, y1, true)) {
        y1++;
    }
    int y2 = img.getHeight() - 1;
    while (y2 >= 0 && isLineEmpty(img, y2, true)) {
        y2--;
    }

    return new Rectangle(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
 
Example 9
Project: campominadobot   File: Utils.java   View Source Code Vote up 5 votes
/**
 * Conta a quantidade de pixels com a cor {@code rgb} passada por parĂ¢metro
 *
 * @param image imagem
 * @param rgb cor rgb
 * @return quantidade de pixels encontrados da cor {@code rgb}
 */
public static int countColor(BufferedImage image, int rgb) {
    int count = 0;
    for (int x = 0; x < image.getWidth(); x++) {
        for (int y = 0; y < image.getHeight(); y++) {
            if (image.getRGB(x, y) == rgb) {
                count++;
            }
        }
    }
    return count;
}
 
Example 10
Project: openjdk-jdk10   File: JpegImageColorSpaceTest.java   View Source Code Vote up 5 votes
public static void main(String args[]) throws Exception {

        String fileName = "nomarkers.jpg";
        String sep = System.getProperty("file.separator");
        String dir = System.getProperty("test.src", ".");
        String filePath = dir+sep+fileName;
        System.out.println("Test file: " + filePath);
        File imageFile = new File(filePath);

        BufferedImage bufferedImage = ImageIO.read(imageFile);
        int imageWidth = bufferedImage.getWidth();
        int imageHeight = bufferedImage.getHeight();

        for (int i = 0; i < imageWidth; i++) {
            for(int j = 0; j < imageHeight; j++) {
                /*
                * Since image is white we check individual pixel values from
                * BufferedImage to verify if ImageIO.read() is done with proper
                * color space or not.
                */
                if (bufferedImage.getRGB(i, j) != Color.white.getRGB()) {
                    // color space is not proper
                    throw new RuntimeException("ColorSpace is not determined "
                            + "properly by ImageIO");
               }
            }
        }
    }
 
Example 11
Project: QN-ACTR-Release   File: EnlargePlotDistGraph.java   View Source Code Vote up 5 votes
BufferedImage convertType(BufferedImage src, int targetType) {
	if (src.getType() == targetType) {
		return src;
	}
	BufferedImage tgt = new BufferedImage(src.getWidth(), src.getHeight(), targetType);
	Graphics2D g = tgt.createGraphics();
	g.drawRenderedImage(src, null);
	g.dispose();
	return tgt;
}
 
Example 12
Project: LCL   File: GetMainColor.java   View Source Code Vote up 5 votes
public static Color getImagePixel(InputStream file) {
    int R = 0;
    int G = 0;
    int B = 0;
    List<String> list = new ArrayList<String>();
    BufferedImage bi = null;
    try {
        bi = ImageIO.read(file);
    } catch (Exception e) {
        e.printStackTrace();
    }
    int width = bi.getWidth();
    int height = bi.getHeight();
    int sum = width * height;
    int minx = bi.getMinX();
    int miny = bi.getMinY();
    for (int i = minx; i < width; i++) {
        for (int j = miny; j < height; j++) {
            int pixel = bi.getRGB(i, j);
            R = (pixel & 0xff0000) >> 16;
            G = (pixel & 0xff00) >> 8;
            B = (pixel & 0xff);
            list.add(R + "-" + G + "-" + B);
        }
    }
    return getMaxCount(list);
}
 
Example 13
Project: Assimp-Tutorial-LWJGL-3   File: Texture.java   View Source Code Vote up 4 votes
private static TextureResource LoadTexture(String fileName)
{
	try
	{
		BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName));
		int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());

		ByteBuffer buffer = Util.CreateByteBuffer(image.getHeight() * image.getWidth() * 4);
		boolean hasAlpha = image.getColorModel().hasAlpha();

		for(int y = 0; y < image.getHeight(); y++)
		{
			for(int x = 0; x < image.getWidth(); x++)
			{
				int pixel = pixels[y * image.getWidth() + x];

				buffer.put((byte)((pixel >> 16) & 0xFF));
				buffer.put((byte)((pixel >> 8) & 0xFF));
				buffer.put((byte)((pixel) & 0xFF));
				if(hasAlpha)
					buffer.put((byte)((pixel >> 24) & 0xFF));
				else
					buffer.put((byte)(0xFF));
			}
		}

		buffer.flip();

		TextureResource resource = new TextureResource();
		glBindTexture(GL_TEXTURE_2D, resource.GetId());

		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

		return resource;
	}
	catch(Exception e)
	{
		e.printStackTrace();
		System.exit(1);
	}
	
	return null;
}
 
Example 14
Project: PekaED   File: SetMapPositionDialog.java   View Source Code Vote up 4 votes
public MapPanel(JSpinner sx, JSpinner sy, JComboBox ci) {
	this.sx = sx;
	this.sy = sy;
	this.ci = ci;
	
	addMouseListener(this);
	
	ci.addActionListener(new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			repaint();
		}
		
	});
	
	try {
		bg = ImageIO.read(new File(Settings.BASE_PATH + File.separatorChar + "gfx" + File.separatorChar + "MAP.bmp"));
		iconSheet = ImageIO.read(new File(Settings.BASE_PATH + File.separatorChar + "gfx" + File.separatorChar + "PK2STUFF.bmp"));
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	for (int i = 0; i < 22; i++) {
		iconList.add(iconSheet.getSubimage((i * 28) + 1, iconSheet.getHeight() - 28, 27, 27));
	}
	
	for (int i = 0; i < iconList.size(); i++) {
		BufferedImage bb = iconList.get(i);
		BufferedImage b2 = new BufferedImage(27, 27, BufferedImage.TYPE_INT_ARGB);
		
		int oldRGB = new Color(155, 232, 224).getRGB();

		for (int x = 0; x < bb.getWidth(); x++) {
			for (int y = 0; y < bb.getHeight(); y++) {
				if (bb.getRGB(x, y) != oldRGB) {
					b2.setRGB(x, y, bb.getRGB(x, y));
				}
			}
		}
	    
	    iconList.set(i, b2);
	}
}
 
Example 15
Project: jdk8u-jdk   File: D3DPaints.java   View Source Code Vote up 4 votes
/**
 * Returns true if the given TexturePaint instance can be used by the
 * accelerated BufferedPaints.Texture implementation.
 *
 * A TexturePaint is considered valid if the following conditions
 * are met:
 *   - the texture image dimensions are power-of-two
 *   - the texture image can be (or is already) cached in a D3D
 *     texture object
 */
@Override
public boolean isPaintValid(SunGraphics2D sg2d) {
    TexturePaint paint = (TexturePaint)sg2d.paint;
    D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
    BufferedImage bi = paint.getImage();

    // verify that the texture image dimensions are pow2
    D3DGraphicsDevice gd =
        (D3DGraphicsDevice)dstData.getDeviceConfiguration().getDevice();
    int imgw = bi.getWidth();
    int imgh = bi.getHeight();
    if (!gd.isCapPresent(CAPS_TEXNONPOW2)) {
        if ((imgw & (imgw - 1)) != 0 || (imgh & (imgh - 1)) != 0) {
            return false;
        }
    }
    // verify that the texture image is square if it has to be
    if (!gd.isCapPresent(CAPS_TEXNONSQUARE) && imgw != imgh)
    {
        return false;
    }

    SurfaceData srcData =
        dstData.getSourceSurfaceData(bi, sg2d.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    if (!(srcData instanceof D3DSurfaceData)) {
        // REMIND: this is a hack that attempts to cache the system
        //         memory image from the TexturePaint instance into a
        //         D3D texture...
        srcData =
            dstData.getSourceSurfaceData(bi, sg2d.TRANSFORM_ISIDENT,
                                         CompositeType.SrcOver, null);
        if (!(srcData instanceof D3DSurfaceData)) {
            return false;
        }
    }

    // verify that the source surface is actually a texture
    D3DSurfaceData d3dData = (D3DSurfaceData)srcData;
    if (d3dData.getType() != D3DSurfaceData.TEXTURE) {
        return false;
    }

    return true;
}
 
Example 16
Project: OpenJSharp   File: JFIFMarkerSegment.java   View Source Code Vote up 4 votes
JFIFThumbUncompressed(BufferedImage thumb) {
    thumbnail = thumb;
    thumbWidth = thumb.getWidth();
    thumbHeight = thumb.getHeight();
    name = null;  // not used when writing
}
 
Example 17
Project: GameResourceBot   File: Preprocessor.java   View Source Code Vote up 4 votes
public static List<File> cropMasked(BufferedImage image) throws IOException {
    // now we iterate over the rows and remove the masked areas since the
    // text we want to read is underneath it
    WritableRaster raster = image.getRaster();
    List<Integer> rowsToRemove = new ArrayList<>();
    for (int yy = 0; yy < image.getHeight(); yy++) {
        int masked = 0;
        for (int xx = 0; xx < image.getWidth(); xx++) {
            if (matchColor(getPixelValue(raster, xx, yy), Color.MAGENTA)) {
                masked++;
            }
        }
        float maskAmount = masked > 0 ? (float) masked / (float) image.getWidth() : 0;
        if (maskAmount > 0.02f) {
            rowsToRemove.add(yy);
        }
    }
    List<SubImage> subImages = extractSubimageBetweenMaskedRows(rowsToRemove, image.getHeight(), 50);
    List<File> result = new ArrayList<>(subImages.size() * 3);
    int i = 0;
    for (SubImage subImage : subImages) {
        BufferedImage cut = image.getSubimage(0, subImage.y, image.getWidth(), subImage.height);

        File tempFile;

        tempFile = File.createTempFile("subImage_" + i + "_c1", ".png", TMP_FILE_DIR);
        tempFile.deleteOnExit();
        ImageIO.write(cut.getSubimage(50, 0, 200, cut.getHeight()), "png", tempFile);
        result.add(tempFile);

        tempFile = File.createTempFile("subImage_" + i + "_c2", ".png", TMP_FILE_DIR);
        tempFile.deleteOnExit();
        ImageIO.write(cut.getSubimage(255, 0, 200, cut.getHeight()), "png", tempFile);
        result.add(tempFile);

        tempFile = File.createTempFile("subImage_" + i + "_c3", ".png", TMP_FILE_DIR);
        tempFile.deleteOnExit();
        ImageIO.write(cut.getSubimage(465, 0, 200, cut.getHeight()), "png", tempFile);
        result.add(tempFile);

        i++;
    }
    return result;
}
 
Example 18
Project: jdk8u-jdk   File: JFIFMarkerSegment.java   View Source Code Vote up 4 votes
JFIFThumbUncompressed(BufferedImage thumb) {
    thumbnail = thumb;
    thumbWidth = thumb.getWidth();
    thumbHeight = thumb.getHeight();
    name = null;  // not used when writing
}
 
Example 19
Project: GIFKR   File: ImageTools.java   View Source Code Vote up 3 votes
public static BufferedImage getChannel2(BufferedImage img, int channel) {

		BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);

		int[] oldd = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
		int[] newd = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();

		for(int i = 0; i < newd.length; i++) {
			newd[i] = oldd[i] & channel;
		}

		return img2;

	}
 
Example 20
Project: FreeCol   File: InformationPanel.java   View Source Code Vote up 3 votes
/**
 * Creates the outer layout of the Information Panel.
 *
 * Called by {@link #InformationPanel(FreeColClient, String, FreeColObject, ImageIcon)}
 *      and {@link #InformationPanel(FreeColClient, String[], FreeColObject[], ImageIcon[])}
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @return A new MigLayout containing the outer layout
 */
private static MigLayout createLayout(FreeColClient freeColClient) {
    BufferedImage skin = getSkin(freeColClient);
    int w = skin.getWidth();
    int h = skin.getHeight();
    return new MigLayout("wrap 1, insets " + (h-290) + " 10 10 10",
            "[" + (w-2*10) + "]", "[240]10[20]");
}