Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. // function resizeImage To adjust the zooming level
  2. public BufferedImage resizeImage(BufferedImage pic , int zoomState) {
  3. if (zoomState >= 0) {
  4. return zoomIn(pic = RotationWithAngle(pic, 0), zoomState + 1);
  5. } else {
  6. return zoomOut(pic = RotationWithAngle(pic, 0), zoomState * -1 + 1);
  7. }
  8.  
  9. }
  10.  
  11.  
  12. // Zooming Methods.---------------------------------------------------
  13. // Function For ZoomIn
  14. public BufferedImage zoomIn(BufferedImage bi, int scale) {
  15. GraphicsEnvironment ge = GraphicsEnvironment
  16. .getLocalGraphicsEnvironment();
  17. // GraphicsDevice[] gs = ge.getScreenDevices();
  18. // int screenWidth = 0;
  19. // int screenHeight = 0;
  20. // for (int i = 0; i < gs.length; i++) {
  21. // DisplayMode dm = gs[i].getDisplayMode();
  22. // screenWidth = dm.getWidth();
  23. // screenHeight = dm.getHeight();
  24. // }
  25. int width = scale * bi.getWidth();
  26. int height = scale * bi.getHeight();
  27. BufferedImage biScale = new BufferedImage(width, height, bi.getType());
  28. for (int i = 0; i < width; i++)
  29. for (int j = 0; j < height; j++)
  30. biScale.setRGB(i, j, bi.getRGB(i / scale, j / scale));
  31.  
  32. return biScale;
  33.  
  34. }
  35.  
  36. // Function For ZoomOut
  37. public BufferedImage zoomOut(BufferedImage bi, int d) {
  38. int width = (bi.getWidth() / d);
  39. int height = (bi.getHeight() / d);
  40. BufferedImage biScale = new BufferedImage(width, height, bi.getType());
  41. for (int i = 0; i < width; i++)
  42. for (int j = 0; j < height; j++)
  43. biScale.setRGB(i, j, bi.getRGB(i * d, j * d));
  44. return biScale;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement