# BufferedImage imageScaling

Page 1 of 1

## 0 Replies - 496 Views - Last Post: 16 November 2009 - 12:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=139462&amp;s=b8548a23a78727e4980cb19160f4565f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 MINGxDOG

Reputation: 0
• 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..

```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

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }