- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 BufferedImage i
,我想得到 Color来自该图像
的某个像素包括 alpha 值。使用 x
和 y
坐标标识像素。
这是我尝试过的:
Color c = new Color(i.getRGB(x, y));
出于某种原因,新的颜色对象包含正确的 RGB,但 alpha 丢失了。
我做错了什么?
提前致谢
最佳答案
您正在使用的单参数 Color
构造函数会丢弃 alpha 信息。改用双参数版本并为 hasalpha
传入 true
:
Color c = new Color(i.getRGB(x, y), true);
相关Javadoc :
Color(int rgb)
Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
Color(int rgba, boolean hasalpha)
Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
关于java - bufferedImage.getRGB(x, y) 不产生 alpha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10726594/
我是 Java 新手。我从Java教程Oracle中看到了下面的代码。我正在努力理解此代码片段的用途: public synchronized int getRGB() { r
第一次调用 getRGB 它返回白色,但第二次调用它时,它返回黑色。 为什么 BufferedImage 的 getRGB 在我第二次调用后返回不同的值? 最佳答案 因为数据改变了? (可能通过增量加
如果我要 int RGB = image.getRGB(x,y),其中 x 和 y 是 image 的透明像素的坐标,那么RGB 的值是?空? 最佳答案 它基本上可以是任何东西。 Alpha 分量与
这段代码的目的是提取 turtle.jpg 中每个像素的每个 RGB 值,但由于某种原因,它给出了一个越界的索引错误。寻求帮助,谢谢。 int j=1; int i=1; BufferedImage
所以,我正在尝试 BufferedImage 中特定像素的颜色... public void LoadImageLevel (BufferedImage image) { int w = im
我使用方法 BufferedImage.getRGB(...) 从 BufferedImage 获取 int 数组,但是当我尝试访问数组中的那些 int 时,我收到 ArrayIndexOutOfBo
我正在学习java,我正在尝试从像素获取RGB信息。我设法做到了这一点,但是,我想了解为什么当我打印出原始的 getRGB() 值时,我得到一个带有减号的不完整的二进制数: -100110011001
我想创建一种新颜色,因为当我使用 .getRGB() 时它工作得很好,但只注册了几种颜色。 这是我的代码,它适用于蓝色和黄色: if (!convergence(z0)){
我正在尝试将图像转换为矩阵并将其转换回来,但是两张图片不同:将其转换为矩阵: public int[][] getMatrixOfImage(BufferedImage bufferedImage)
如果我以这种方式创建一个 BufferedImage: BufferedImage image = new BufferedImage(4, 3, BufferedImage.TYPE_BYT
我使用此方法获取图像中像素的整数值: int colour = img.getRGB(x, y); 然后我打印出这些值,我看到黑色像素对应于“-16777216”之类的值,一种蓝色对应于“-16755
您好,我正在尝试从 C# 转换 Java 应用程序,这是我遇到的唯一问题..:旁注:那个 Bitmap 类是我做的一个类。 Java 代码: for (int x = 0; x < x
我无法找出解决此问题的方法请帮助我。 我试图通过在 collapseToolbarLayout 中提取图像中的颜色来更改工具栏的颜色,这是我的 java 代码 public class Toolbar
我试图实现 Hill Cipher通过抓取图像像素来对图像进行算法。事实证明,小图像加载得很好。 但是对于较大的图像(8MP或12MP),加载速度很慢;因此写入图像也很慢。 我使用 bufferedI
我正在使用这种方法获取图像中像素的整数值: int colour = img.getRGB(x, y); 然后我打印出这些值,我看到黑色像素对应于“-16777216”之类的值,一种蓝色对应“-167
我正在使用 poi.apache 阅读 xslx 工作簿,我想获取单元格的 RGB 颜色代码。当我尝试从 XSSFColor 获取 RGB 代码时,即使我知道那里有颜色,它也会返回 null。 for
我是java图像处理新手。实际上我想做的是将图像的所有像素值保存到数组 rgbArray[] 中,问题是我在数组的所有索引中得到相同的值,即数组的所有索引都具有相同的值。部分代码如下: int[] r
我正在编写一个带有简单隐写术实现的程序。 我有一个问题,因为如果我对一个像素使用 setRGB 然后 getRGB 我会得到不同的值。我读到 setRGB 和 getRGB 不是字节和位操作的最佳主意
我正在使用Applet编写一个小游戏。我希望能够检查屏幕上像素的颜色。但是,当我在游戏循环(反复执行的 while 循环)中的缓冲图像上使用 .getRGB() 时,即使像素颜色实际上从未改变,它也会
我正在使用机器人截取屏幕截图,然后在这些屏幕截图中搜索较小的图像。由于 Gamma 校正,这适用于 Windows 但不适用于 OS X。我能想到的最佳解决方案是简单地匹配相似的颜色,而不是完全匹配颜
我是一名优秀的程序员,十分优秀!