Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mega2223 committed Oct 28, 2021
2 parents f9a6a14 + b3390d6 commit 29cc484
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
Expand All @@ -27,7 +28,12 @@ public static BufferedImage createFlipped(BufferedImage image) {
}

public static Image createFlipped(Image image){
return createFlipped(image);
BufferedImage bufferedImage = new BufferedImage(
image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_4BYTE_ABGR);
bufferedImage.createGraphics().drawImage(image,0,0,null);
return createFlipped(bufferedImage);
}

public static Image getScaledGraph(Dimension legal, double grid, GraphRenderer renderer){
Expand All @@ -41,6 +47,22 @@ public static Image getScaledGraph(Dimension legal, double grid, GraphRenderer r
return readj;
}

public static BufferedImage rotateImage(double degrees, BufferedImage image){
double rads = Math.toRadians(degrees);
double sin = Math.abs(Math.sin(rads));
double cos = Math.abs(Math.cos(rads));
int w = (int) Math.floor(image.getWidth() * cos + image.getHeight() * sin);
int h = (int) Math.floor(image.getHeight() * cos + image.getWidth() * sin);
BufferedImage rotatedImage = new BufferedImage(w, h, image.getType());
AffineTransform at = new AffineTransform();
at.translate(w / 2, h / 2);
at.rotate(rads,0, 0);
at.translate(-image.getWidth() / 2, -image.getHeight() / 2);
AffineTransformOp rotateOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
rotateOp.filter(image,rotatedImage);
return rotatedImage;
}

public static Image getImageByURL(String url) throws IOException {
return getImageByURL(new URL(url));
}
Expand Down

0 comments on commit 29cc484

Please sign in to comment.