Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 11-14 of 14 total

Java - HalfFlipH / HalfFlipW

	public BufferedImage halfFlipW(BufferedImage bi)
	{
		int width = bi.getWidth();
		int height = bi.getHeight();
		
		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width; i++)
			for(int j=0; j<height/2; j++)
			{
				biFlip.setRGB(i, j, bi.getRGB(i, j));
				biFlip.setRGB(i, (height-1)-j, bi.getRGB(i, j));
			}
		
		return biFlip;
	}


	public BufferedImage halfFlipH(BufferedImage bi)
	{
		int width = bi.getWidth();
		int height = bi.getHeight();
		
		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width/2; i++)
			for(int j=0; j<height; j++)
			{
				biFlip.setRGB(i, j, bi.getRGB(i, j));
				biFlip.setRGB((width-1)-i, j, bi.getRGB(i, j));
			}
		
		return biFlip;
	}

Java - FlipH / FlipW

public BufferedImage flipH(BufferedImage bi)
	{
		int width = bi.getWidth();
		int height = bi.getHeight();
		
		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biFlip.setRGB((width-1)-i, j, bi.getRGB(i, j));
		
		return biFlip;
	}


	
	public BufferedImage flipW(BufferedImage bi)
	{
		int width = bi.getWidth();
		int height = bi.getHeight();
		
		BufferedImage biFlip = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biFlip.setRGB(i, (height-1)-j, bi.getRGB(i, j));
		
		return biFlip;
	}

Java - ZoomOUT image

public BufferedImage zoomOut(BufferedImage bi, int scale)
	{
		int width = bi.getWidth() / scale;
		int height = bi.getHeight() / scale;
		
		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biScale.setRGB(i, j, bi.getRGB(i*scale, j*scale));
		
		return biScale;
	}

Java - ZoomIN Image

public BufferedImage zoomIn(BufferedImage bi, int scale)
	{
		int width = scale * bi.getWidth();
		int height = scale * bi.getHeight();
		
		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
		
                // Cicla dando un valore medio al pixel corrispondente
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biScale.setRGB(i, j, bi.getRGB(i/scale, j/scale));
		
		return biScale;
	}
« Newer Snippets
Older Snippets »
Showing 11-14 of 14 total