Advertisement
mahmudkuet

Untitled

Feb 14th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1.     public static BufferedImage sclae2(BufferedImage img, int w2, int h2){
  2.         int w1 = img.getWidth();
  3.         int h1 = img.getHeight();
  4.         BufferedImage output = new BufferedImage(w2, h2, BufferedImage.TYPE_INT_RGB);
  5.         double x_ratio = (double)w1/w2;
  6.         double y_ratio = (double)h1/h2;
  7.         for(int i=0; i<w2; i++){
  8.             for (int j = 0; j < h2; j++) {
  9.                 int rgb = img.getRGB((int)Math.floor(i*x_ratio), (int)Math.floor(j*y_ratio));
  10.                 output.setRGB(i, j, rgb);
  11.             }
  12.         }
  13.         return output;
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement