Skip to content
This repository has been archived by the owner on Feb 11, 2023. It is now read-only.

Commit

Permalink
[+] 裁剪图片方法
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Sep 15, 2018
1 parent 2c595cd commit 1c7be1b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/cc/moecraft/icq/plugins/osubot/utils/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,38 @@
*/
public class ImageUtils
{
/**
* 裁剪图片方法
* @param original 图像源
* @param startX 裁剪开始x坐标
* @param startY 裁剪开始y坐标
* @param endX 裁剪结束x坐标
* @param endY 裁剪结束y坐标
* @return 处理后的
*
* @author @FrightingForAmbition
*/
public static BufferedImage cropImage(BufferedImage original, int startX, int startY, int endX, int endY)
{
int width = original.getWidth();
int height = original.getHeight();

if (startX == -1) startX = 0;
if (startY == -1) startY = 0;
if (endX == -1) endX = width - 1;
if (endY == -1) endY = height - 1;

BufferedImage result = new BufferedImage(endX - startX, endY - startY, 4);

for (int x = startX; x < endX; ++x)
{
for (int y = startY; y < endY; ++y)
{
int rgb = original.getRGB(x, y);
result.setRGB(x - startX, y - startY, rgb);
}
}

return result;
}
}

0 comments on commit 1c7be1b

Please sign in to comment.