javafx 读取 javafx.scene.image.Image 到 ImageIO.write(),从 CMYK 到 RGB
javafx read javafx.scene.image.Image to ImageIO.write(), from CMYK to RGB
我想做的是从 FileChooser 中读取图像并将其写入文件。我必须将图像存储在 javafx.scene.image.Image 中,以便我可以显示它并将其剪辑在一个圆圈内。我在尝试将从 javafx.scene.image.Image 获得的图像写入文件时遇到一点问题。转换过程不流畅,从 CMYK 转换为 RGB(因此将我的图片变成了一些粉红色的东西。
拜托,我检查了很多其他来源,但没有人能够给我一个显着的解决方案
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(parent);
// get Image from selectedFile
Image userImg = = new Image( selectedFile.toURI().toURL().toString() );
if ( userImg != null ) {
String format = "jpg";
String filename = "d:\pictureName."+ format;
File file = new File(filename);
// convert Image to BufferedImage
BufferedImage bufferedImage = SwingFXUtils.fromFXImage( userImg, null);
try {
// this is where i want to convert the color mode
// from cmyk to rgb, before i write it to file
ImageIO.write( bufferedImage, format, file );
} catch (IOException e) {
System.out.println("Exception :: "+ e.getMessage() );
}
}
您认为为什么会发生 CMYK 到 RGB 的转换?我怀疑您 "pink thing" 的原因有所不同。找出答案的最简单方法是将输出格式从 jpeg 更改为 png 并查看它是否有所不同。
我认为您又是被这个错误 https://bugs.openjdk.java.net/browse/JDK-8119048 击中的众多人之一,这个错误被认为不够重要,无法修复。如果您阅读其中的评论,您会找到解决方法。基本上这个想法是在转换成没有 alpha 通道的新图像后复制图像。
我真的很想知道还有多少人不得不浪费他们的时间,直到这个错误最终得到足够的重视来修复。
我想做的是从 FileChooser 中读取图像并将其写入文件。我必须将图像存储在 javafx.scene.image.Image 中,以便我可以显示它并将其剪辑在一个圆圈内。我在尝试将从 javafx.scene.image.Image 获得的图像写入文件时遇到一点问题。转换过程不流畅,从 CMYK 转换为 RGB(因此将我的图片变成了一些粉红色的东西。
拜托,我检查了很多其他来源,但没有人能够给我一个显着的解决方案
FileChooser fileChooser = new FileChooser();
File selectedFile = fileChooser.showOpenDialog(parent);
// get Image from selectedFile
Image userImg = = new Image( selectedFile.toURI().toURL().toString() );
if ( userImg != null ) {
String format = "jpg";
String filename = "d:\pictureName."+ format;
File file = new File(filename);
// convert Image to BufferedImage
BufferedImage bufferedImage = SwingFXUtils.fromFXImage( userImg, null);
try {
// this is where i want to convert the color mode
// from cmyk to rgb, before i write it to file
ImageIO.write( bufferedImage, format, file );
} catch (IOException e) {
System.out.println("Exception :: "+ e.getMessage() );
}
}
您认为为什么会发生 CMYK 到 RGB 的转换?我怀疑您 "pink thing" 的原因有所不同。找出答案的最简单方法是将输出格式从 jpeg 更改为 png 并查看它是否有所不同。
我认为您又是被这个错误 https://bugs.openjdk.java.net/browse/JDK-8119048 击中的众多人之一,这个错误被认为不够重要,无法修复。如果您阅读其中的评论,您会找到解决方法。基本上这个想法是在转换成没有 alpha 通道的新图像后复制图像。 我真的很想知道还有多少人不得不浪费他们的时间,直到这个错误最终得到足够的重视来修复。