Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function resizeImage To adjust the zooming level
- public BufferedImage resizeImage(BufferedImage pic , int zoomState) {
- if (zoomState >= 0) {
- return zoomIn(pic = RotationWithAngle(pic, 0), zoomState + 1);
- } else {
- return zoomOut(pic = RotationWithAngle(pic, 0), zoomState * -1 + 1);
- }
- }
- // Zooming Methods.---------------------------------------------------
- // Function For ZoomIn
- public BufferedImage zoomIn(BufferedImage bi, int scale) {
- GraphicsEnvironment ge = GraphicsEnvironment
- .getLocalGraphicsEnvironment();
- // GraphicsDevice[] gs = ge.getScreenDevices();
- // int screenWidth = 0;
- // int screenHeight = 0;
- // for (int i = 0; i < gs.length; i++) {
- // DisplayMode dm = gs[i].getDisplayMode();
- // screenWidth = dm.getWidth();
- // screenHeight = dm.getHeight();
- // }
- int width = scale * bi.getWidth();
- int height = scale * bi.getHeight();
- 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;
- }
- // Function For ZoomOut
- public BufferedImage zoomOut(BufferedImage bi, int d) {
- int width = (bi.getWidth() / d);
- int height = (bi.getHeight() / d);
- 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 * d, j * d));
- return biScale;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement