gpt4 book ai didi

java - 带 TexturePaint 的图标抛出 InternalError : Surface not cachable

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:37:30 29 4
gpt4 key购买 nike

我有一个自定义 Icon,它使用 TexturePaint 作为绘画并在 Graphics2D 对象上调用 fillPolygon

此代码在 JDK6 和 JDK7 上运行良好,但在 JDK8 和 64 位 Linux 下失败(在 64 位 Linux 上尝试了最新的 JDK1.8)。在 Windows 上,这在 JDK8 上运行良好。

用于重现问题的 JDK 的 java -version 命令的输出。

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

重现问题的代码:

import java.awt.*;
import java.awt.image.*;
import javax.swing.*;

public class TexturePaintIconTest {

private static class CustomIcon implements Icon{

private static final int[] sXArray = new int[]{2, 5, 7, 12, 12, 4, 1, 1, 2};
private static final int[] sYArray = new int[]{4, 4, 2, 2, 11, 11, 8, 5, 4};
private static final int sNumberOfPoints = 9;

@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.translate(x,y);

Graphics2D g2d = (Graphics2D) g;
Color fillColor = new Color( 140, 25, 25, 35);
g2d.setPaint(createPatternPaint(fillColor));
g2d.fillPolygon(sXArray, sYArray, sNumberOfPoints);

g.translate(-x, -y);
}

private Paint createPatternPaint(Color color ){
int[] colors = new int[]{color.getRGB(), 0};
IndexColorModel colorModel = new IndexColorModel(1, 2, colors, 0, true, -1, DataBuffer.TYPE_BYTE);
BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_INDEXED, colorModel);
DataBufferByte dataBuffer = (DataBufferByte) image.getRaster().getDataBuffer();
byte[] data = dataBuffer.getData();
data[0] = 0;
data[1] = 1;
data[2] = 1;
data[3] = 0;
return new TexturePaint(image, new Rectangle(2, 2));
}

@Override
public int getIconWidth() {
return 16;
}

@Override
public int getIconHeight() {
return 16;
}
}

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame testFrame = new JFrame("TestFrame");

JLabel label = new JLabel("Label with icon", new CustomIcon(), SwingConstants.LEFT);
testFrame.add(label);

testFrame.pack();
testFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
testFrame.setVisible(true);
}
});
}

}

运行main方法会出现如下错误

Exception in thread "AWT-EventQueue-0" java.lang.InternalError: Surface not cachable
at sun.java2d.xr.XRPaints$XRTexture.getAccSrcSurface(XRPaints.java:211)
at sun.java2d.xr.XRPaints$XRTexture.isPaintValid(XRPaints.java:224)
at sun.java2d.xr.XRPaints.isValid(XRPaints.java:75)
at sun.java2d.xr.XRSurfaceData.getMaskFill(XRSurfaceData.java:205)
at sun.java2d.SurfaceData.validatePipe(SurfaceData.java:675)
at sun.java2d.xr.XRSurfaceData.validatePipe(XRSurfaceData.java:123)
at sun.java2d.SunGraphics2D.validatePipe(SunGraphics2D.java:446)
at sun.java2d.pipe.ValidatePipe.validate(ValidatePipe.java:55)
at sun.java2d.pipe.ValidatePipe.fillPolygon(ValidatePipe.java:147)
at sun.java2d.SunGraphics2D.fillPolygon(SunGraphics2D.java:2389)
at com.luciad.internal.lucy.map.TexturePaintIconTest$CustomIcon.paintIcon(TexturePaintIconTest.java:22)

我已经在 J​​ava 错误数据库(official oneopenjdk one)中进行了搜索,但没有找到可以解释这一点的错误报告。我的自定义图标是不是做错了什么,还是偶然发现了 JDK 错误?

最佳答案

如果相同的代码根据 JVM 的不同而不同,那一定是一个错误,因为它是代码中唯一特定于操作系统的部分

关于java - 带 TexturePaint 的图标抛出 InternalError : Surface not cachable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26631979/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com