-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7515197
commit 7daf4bd
Showing
2 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package simplexity.entityicons; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.Graphics2D; | ||
import java.awt.RenderingHints; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class Rescaler { | ||
|
||
public static BufferedImage rescaleImage(String path, int multiplier, int originalSize) { | ||
BufferedImage originalImage; | ||
try { | ||
path = path.substring(5); | ||
File file = new File(path); | ||
originalImage = ImageIO.read(file); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
int size = multiplier * originalSize; | ||
BufferedImage resizedImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); | ||
Graphics2D graphicsImage = resizedImage.createGraphics(); | ||
graphicsImage.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); | ||
graphicsImage.drawImage(originalImage, 0,0, size, size,null); | ||
graphicsImage.dispose(); | ||
return resizedImage; | ||
} | ||
} |