【发布时间】:2019-03-21 18:56:58
【问题描述】:
我正在处理一个项目,其中一项要求是扫描包含不同图像的文件夹。我需要找到一种方法来扫描文件夹并将每个图像添加到图像数组中。这是我想做的事
public class ImageScan {
private ArrayList<Image> images = new ArrayList<>();
public void loadImages() {
ArrayList<Image> image_Array = new ArrayList<>();
File file = new File("data/images");
BufferedImage image = ImageIO.read(file);
while(image.hasNextImage()) {//hasnextImage() is not a valid method,
//just to express my idea.
Image image = //save read Image to an image instance
//here all I want to do is add each image I obtain into an
//arrayList of images
image_Array.add(image);
}//end of while
this.setImages(image_Array);// i set image_Array using getter method
}//end of loadData method
}//end of class
【问题讨论】:
-
你忘了问一个具体的问题。
-
一个 Q. 你想怎么扫描它?有手机吗?
-
不,不是通过电话,类似于使用扫描器类扫描文件中的句子行,但不是扫描句子,而是扫描图像。更像是说“将读取的图像保存到 Image 实例。
-
您需要实际的像素数据,还是只想扫描图像文件,然后处理这些(即,您想对图像做什么?之后)?如果您同时将任意数量的图像读入内存,您可能会在某个时候耗尽内存。一个更具可扩展性的解决方案可能是一次处理一个(或另一个固定数量的)图像,然后移动到下一个。
标签: java image arraylist file-io javax.imageio