读取缓冲的图像会显示透明度,但输出错误的Alpha值

时间:2019-06-09 02:20:27

标签: java image bufferedimage

我正在尝试从JFileChooser加载文件,然后将其转换为BufferedImage进行裁剪。我正在检测图像的像素颜色以确定在哪里裁剪。但是,如果我输入透明图像,则透明部分将被视为黑色并输出颜色值(0、0、0、255)。

我使用ImageIO将文件选择器中的文件读取到缓冲的图像中。

inputFile = chooser.getSelectedFile();

// try and catch to see if file being read exist
try {

    BufferedImage loadedImage = ImageIO.read(inputFile);

    // the input image is a resized version of the loaded image to fit the button size
    inputImage = CustomizationTool.resize(loadedImage, CustomizationTool.selectButtonDimension, CustomizationTool.selectButtonDimension);

    // break the inputed word into characters
    wordList = CustomizationTool.loadWord(loadedImage);

    // loop through each character to crop the character from the file and resize it
    for(int i = 0; i < wordList.size(); i++) 

        wordList.set(i, CustomizationTool.resize(
                CustomizationTool.cropToFit(inputImage), CustomizationTool.selectButtonDimension, CustomizationTool.selectButtonDimension));


    selectButton.setIcon(new ImageIcon(inputImage));

    // fill the base variables in the lists for the input image
    fillMatchingPixels();

} catch (IOException error) {

    System.out.println("input file does not exsist");

}

我尝试使用Color.getAlpha()打印透明度值。但是,我得到的结果是255,这意味着它是完全不透明的。

0 个答案:

没有答案