BufferedImage imageScaling

bi-linear interpolation and Nearest Neighbor Interpolation with backwa

Page 1 of 1

0 Replies - 453 Views - Last Post: 16 November 2009 - 12:33 PM Rate Topic: -----

#1 MINGxDOG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 16-November 09

BufferedImage imageScaling

Posted 16 November 2009 - 12:33 PM

I really cannot think about it..
how to use bi-linear interpolation and Nearest Neighbor Interpolation with backward mapping?
of course the code below is not yet finish..
I really have no idea..
please help..


import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.*;
import java.lang.Math.*;


public class ImageProcessor
{	
	public static BufferedImage convert(Image img)
	{
		BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
		Graphics bg = bi.getGraphics();
		bg.drawImage(img, 0, 0, null);
		bg.dispose();
		return bi;
	}
	public static BufferedImage imageScaling(Image img, double sX, double sY, int type)
	{

	BufferedImage bufImg = convert(img);
		
		int width = bufImg.getWidth();
		int height = bufImg.getHeight();
		
		double newWidth = width * sX;
		double newHeight = height * sY;
				
		for(int j = 0; j < newHeight; j++)
		{

			for(int i = 0; i < newWidth; i++)
			{

				int values = bufImg.getRGB(i,j);

				Color oldColor = new Color(values);
				
				int red = oldColor.getRed();		
				int green = oldColor.getGreen();	
				int blue = oldColor.getBlue();	
				
					 
			Color newColor = new Color(red, green, blue);
					bufImg.setRGB(i, j, newColor.getRGB())
			
			}
		}
		return bufImg;

	}
}

This post has been edited by MINGxDOG: 16 November 2009 - 12:34 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1