[英]Java SWT graphical context - How to get the color at the coordinates of a gradient rectangle?
I have a gradient rectangle, drawn with SWT graphical context. 我有一个渐变矩形,使用SWT图形上下文绘制。 How can I retrieve a color, which is used at a distinct point inside of the rectangle? 如何获取在矩形内部不同点使用的颜色?
e.gc.setForeground(color_highlight_shadow);
e.gc.setBackground(color_normal_shadow);
e.gc.fillGradientRectangle(0, 1, 100, 100, false);
You can get it by copying the area (your pixel) into an image and extracting the RGB from this image: 您可以通过将区域(像素)复制到图像中并从该图像中提取RGB来获得它:
final Image image = new Image(display, 1, 1);
e.gc.copyArea(image, x, y);
ImageData data = image.getImageData();
int pixelValue = imageData.getPixel(0,0);
PaletteData palette = data.palette;
RGB rgb = palette.getRGB(pixelValue);
System.out.println("RGB value for (x,y): " + rgb);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.