java.io.FileNotFoundException:Image.IO.write上的访问被拒绝

时间:2017-03-28 21:58:55

标签: image-processing filenotfoundexception access-denied

以4x8和8x16网格裁剪64x128像素图像并将其保存在临时文件夹中以从图像分类中提取要素。虽然我在多个图像的循环中执行此操作(我裁剪第一个图像,获取8x16子图像,提取每个子图像的功能,移动到下一个图像并覆盖现有的子图像)我得到一个“文件未找到”异常随机网格单元,因为拒绝所述网格单元的访问。仅在处理大量(例如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\2.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)

在裁剪部分发生错误,我的其余方法应该可以正常工作。

1 个答案:

答案 0 :(得分:0)

在每张图片修复问题后清除Temp文件夹。