Я использую следующий код для «обрезки изображения», однако он игнорирует прозрачность, поэтому любые BufferedImages, полученные с помощью этого метода, полностью непрозрачны, и, по-видимому, нет никаких .getARGB () или .setARGB () методы. Как мне обойти это?
private static BufferedImage getCroppedImage(BufferedImage wholeImage, int xPos, int yPos, int width, int height)
{
GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
BufferedImage croppedImage = null;
try
{
GraphicsDevice screen = graphEnv.getDefaultScreenDevice();
GraphicsConfiguration gc = screen.getDefaultConfiguration();
croppedImage = gc.createCompatibleImage(width, height, Transparency.BITMASK);
}
catch (Exception e)
{
new errorWindow(e, "crop, in Images");
}
if (croppedImage == null)
{
croppedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
}
int[] pixels = new int[width * height];
wholeImage.getRGB(xPos, yPos, width, height, pixels, 0, width);
croppedImage.setRGB(0, 0, width, height, pixels, 0, width);
return croppedImage;
}