java.io.FileNotFoundException:Image.IO.write 拒绝访问
java.io.FileNotFoundException: Access denied on Image.IO.write
我在 4x8 和 8x16 网格中裁剪 64x128 像素图像并将它们保存在临时文件夹中以从中提取特征以进行图像分类。当我在多个图像的循环中执行此操作时(我裁剪第一个图像,获取 8x16 子图像,为每个子图像提取特征,移动到下一个图像并覆盖现有子图像)我在随机网格中得到一个 "File not found" 异常单元格,因为拒绝访问所述网格单元格。只有在处理大量(比如 20 多个)图像时才会发生这种情况。我该如何解决这个问题?
裁剪部分我的代码:
package imageProcess;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Crop_Raster {
BufferedImage src;
BufferedImage dst;
public Crop_Raster(BufferedImage src) {
super();
this.src = src;
}
public void cropImage_4x8() throws IOException{
int filenumber = 1;
for (int y = 0;y<4;y++){
for (int x = 0; x<8;x++){
File output = new File("Temp/"+filenumber+".jpg");
dst = src.getSubimage(16*x,16*y, 16, 16);
ImageIO.write(dst, "jpg", output);
filenumber ++;
}
}
}
public void cropImage_8x16() throws IOException{
int filenumber = 1;
for (int y = 0;y<8;y++){
for (int x = 0; x<16;x++){
File output = new File("Temp/"+filenumber+".jpg");
dst = src.getSubimage(8*x,8*y, 8, 8);
ImageIO.write(dst, "jpg", output);
filenumber ++;
}
}
}
我在处理第 6 个训练图像的第二个子图像时出现以下异常:
java.io.FileNotFoundException: Temp.jpg (Zugriff verweigert)
at java.io.RandomAccessFile.open0(Native Method)
at java.io.RandomAccessFile.open(Unknown Source)
at java.io.RandomAccessFile.<init>(Unknown Source)
at javax.imageio.stream.FileImageOutputStream.<init>(Unknown Source)
at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(Unknown Source)
at javax.imageio.ImageIO.createImageOutputStream(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at imageProcess.Crop_Raster.cropImage_8x16(Crop_Raster.java:38)
at svm.CreateVektor.createVector_8x16(CreateVektor.java:94)
at Main_Test.main(Main_Test.java:107)
错误发生在裁剪部分,我的其他方法应该没问题。
在每个图像后清除 Temp 文件夹解决了问题。
我在 4x8 和 8x16 网格中裁剪 64x128 像素图像并将它们保存在临时文件夹中以从中提取特征以进行图像分类。当我在多个图像的循环中执行此操作时(我裁剪第一个图像,获取 8x16 子图像,为每个子图像提取特征,移动到下一个图像并覆盖现有子图像)我在随机网格中得到一个 "File not found" 异常单元格,因为拒绝访问所述网格单元格。只有在处理大量(比如 20 多个)图像时才会发生这种情况。我该如何解决这个问题?
裁剪部分我的代码:
package imageProcess;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Crop_Raster {
BufferedImage src;
BufferedImage dst;
public Crop_Raster(BufferedImage src) {
super();
this.src = src;
}
public void cropImage_4x8() throws IOException{
int filenumber = 1;
for (int y = 0;y<4;y++){
for (int x = 0; x<8;x++){
File output = new File("Temp/"+filenumber+".jpg");
dst = src.getSubimage(16*x,16*y, 16, 16);
ImageIO.write(dst, "jpg", output);
filenumber ++;
}
}
}
public void cropImage_8x16() throws IOException{
int filenumber = 1;
for (int y = 0;y<8;y++){
for (int x = 0; x<16;x++){
File output = new File("Temp/"+filenumber+".jpg");
dst = src.getSubimage(8*x,8*y, 8, 8);
ImageIO.write(dst, "jpg", output);
filenumber ++;
}
}
}
我在处理第 6 个训练图像的第二个子图像时出现以下异常:
java.io.FileNotFoundException: Temp.jpg (Zugriff verweigert)
at java.io.RandomAccessFile.open0(Native Method)
at java.io.RandomAccessFile.open(Unknown Source)
at java.io.RandomAccessFile.<init>(Unknown Source)
at javax.imageio.stream.FileImageOutputStream.<init>(Unknown Source)
at com.sun.imageio.spi.FileImageOutputStreamSpi.createOutputStreamInstance(Unknown Source)
at javax.imageio.ImageIO.createImageOutputStream(Unknown Source)
at javax.imageio.ImageIO.write(Unknown Source)
at imageProcess.Crop_Raster.cropImage_8x16(Crop_Raster.java:38)
at svm.CreateVektor.createVector_8x16(CreateVektor.java:94)
at Main_Test.main(Main_Test.java:107)
错误发生在裁剪部分,我的其他方法应该没问题。
在每个图像后清除 Temp 文件夹解决了问题。