我正在尝试从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,这意味着它是完全不透明的。