在javadocs之后,我试图扩展一个BufferedImage没有成功的是我的代码:
BufferedImage image = MatrixToImageWriter.getBufferedImage(encoded);
Graphics2D grph = image.createGraphics();
grph.scale(2.0, 2.0);
grph.dispose();
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么它不起作用,有什么帮助吗?
我的问题:我希望能够改变资源图像的亮度,并将其三个实例作为ImageIcons.一个亮度为50%(如此暗),另一个亮度为75%(亮度稍高),最后另一个亮度为100%(与原始图像相同).我也想保持透明度.
我尝试了什么:我已经四处寻找,看起来最好的解决方案是使用RescaleOp,但我无法理解.我不知道scaleFactor和偏移是什么.这是我尝试过的代码.
public void initialize(String imageLocation, float regularBrightness, float focusedBrightness, float pressedBrightness, String borderTitle) throws IOException {
BufferedImage bufferedImage = ImageIO.read(ButtonIcon.class.getResource(imageLocation));
setRegularIcon(getAlteredImageIcon(bufferedImage, regularBrightness));
setFocusedIcon(getAlteredImageIcon(bufferedImage, focusedBrightness));
setPressedIcon(getAlteredImageIcon(bufferedImage, pressedBrightness));
setTitle(borderTitle);
init();
}
private ImageIcon getAlteredImageIcon(BufferedImage bufferedImage, float brightness) {
RescaleOp rescaleOp = new RescaleOp(brightness, 0, null);
return new ImageIcon(rescaleOp.filter(bufferedImage, null));
}
Run Code Online (Sandbox Code Playgroud)
电话会是这样的:
seeATemplateButton.initialize("/resources/templateIcon-regular.png", 100f, 75f, 50f, "See A Template");
//I think my 100f, 75f, 50f variables need to change, but whenever I change them it behaves unexpectedly (changes …Run Code Online (Sandbox Code Playgroud) 我有一个在JLabel中导入的图像.Java中是否有内置函数可用于通过Slider更改图像的亮度和对比度?
我正在Netbeans中创建一个Swing GUI.此GUI的目的是打开(缓冲)图像(在JLabel中作为图标)并在其上应用仿射变换.现在有4个转换,我正在做如下.

现在,每个变换需要两个滑块才能更改X和Y值,但旋转除外,只需要一个.我这样做是因为它比为所有4种类型的变换做四个选项卡要好得多.另外,我希望它是这样的,例如,如果旋转图像,可以通过从下拉列表中选择剪切来剪切相同的旋转图像.
问题是(是):如何重新绘制标签图标并对同一重新绘制的图像应用不同的变换?另外,如何在所选效果上更改JSlider depanding的最小值和最大值?
我正在将 python/Qt GUI 应用程序转换为 Java/Swing。当用户拖动 QColorDialog 中的滑块时,原始应用程序会连续精美地更新场景颜色。如何在 JColorChooser 中获得类似的效果?我发现的所有示例仅在用户单击“应用”或“确定”按钮时更新颜色。当我的用户拖动“红色”滑块时,是否有一种机制可以监听 JColorChooser 中的连续颜色变化?
// How can I listen to every color adjustment?
// (i.e. not just when the user presses "Apply" or "OK"?)
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("color changed");
}
};
Dialog colorDialog = JColorChooser.createDialog(ColorChannelWidget.this,
"Select color for channel 3",
false, // not modal
new JColorChooser(Color.pink),
actionListener, actionListener);
colorDialog.setVisible(true);
Run Code Online (Sandbox Code Playgroud)
编辑:
我要更改的颜色位于动态生成的 OpenGL 场景中。不是静态图像。