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

Commit

Permalink
[+] Image转BufferedImage方法
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Sep 15, 2018
1 parent 1c7be1b commit 0dbffb6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 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 @@ -47,4 +47,28 @@ public static BufferedImage cropImage(BufferedImage original, int startX, int st

return result;
}

/**
* Converts a given Image into a BufferedImage
*
* @param img The Image to be converted
* @return The converted BufferedImage
*
* @author @Sri Harsha Chilakapati
*/
public static BufferedImage toBufferedImage(Image img)
{
if (img instanceof BufferedImage) return (BufferedImage) img;

// Create a buffered image with transparency
BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);

// Draw the image on to the buffered image
Graphics2D bGr = bufferedImage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

// Return the buffered image
return bufferedImage;
}
}

0 comments on commit 0dbffb6

Please sign in to comment.