gpt4 book ai didi

java - 将图像解析为多个图像

转载 作者:行者123 更新时间:2023-11-30 04:56:44 26 4
gpt4 key购买 nike

我正在制作一个带有自定义文本图标的游戏,我想从一个图像加载每个图像。如何将一个图像分割成一堆其他图像,这些图像只是原始图像的一部分?

最佳答案

我认为您正在寻找 CropImageFilter

An ImageFilter class for cropping images. This class extends the basic ImageFilter Class to extract a given rectangular region of an existing Image and provide a source for a new image containing just the extracted region

您必须将其与 FilteredImageSource 一起使用

This class is an implementation of the ImageProducer interface which takes an existing image and a filter object and uses them to produce image data for a new filtered version of the original image.

例如

public class Part extends JPanel {
private Image src;

public Part(Image src) {
this.src = src;
}

public Image create(int xPos, int yPos, int width, int height) {
ImageFilter cropImagefilter = new CropImageFilter(xPos, yPos, width, height); //see constructor detail
FilteredImageSource filteredImageSource = new FilteredImageSource(this.src.getSource(), cropImagefilter)
Image part = createImage(filteredImageSource);
return part;
}
}

关于java - 将图像解析为多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com