Я пытаюсь загрузить файл из 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. Это означает, что он полностью непрозрачный.