像素的最佳方法是什么

像素的最佳方法是什么

本文介绍了读取 JavaFX Canvas 像素的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取 Canvas 内特定坐标的颜色.我已经尝试使用此代码获取快照:

I want to get the color for specific coordinates inside a Canvas. I already tried getting a snapshot using this code:

WritableImage snap = gc.getCanvas().snapshot(null, null);
snap.getPixelReader().getArgb(x, y); //This just gets the color without assigning it.

但是我的申请需要太多时间.我想知道是否还有其他方法可以访问我知道坐标的像素的颜色.

But it just takes too much time for my application. I was wondering if there is any other way to access the color of a pixel for which I know the coordinates.

推荐答案

A Canvas 缓冲通过调用 .在 Canvas 在以后的 ,API 中没有公开指令缓冲区的内部格式.

A Canvas buffers the drawing instructions prescribed by invoking the methods of a GraphicsContext. There are no pixels to read until the Canvas is rendered in a later pulse, and the internal format of the instruction buffer is not exposed in the API.

作为替代方案,考虑绘制成一个 BufferedImage,在这里说明,它允许直接或通过访问图像的像素它的 WritableRaster.将以下行添加到这个完整的示例以 ARGB 顺序输出不透明红色的预期值:ffff0000.

As an alternative, consider drawing into a BufferedImage, illustrated here, which allows access to the image's pixels directly and via its WritableRaster. Adding the following line to this complete example outputs the expected value for opaque red in ARGB order: ffff0000.

System.out.println(Integer.toHexString(bi.getRGB(50, 550)));

这篇关于读取 JavaFX Canvas 像素的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:42