简体   繁体   English

java Vs VB.net中的RGB颜色

[英]RGB colors in java Vs VB.net

I'm no native English speaker, so please excuses any translation errors. 我不是母语为英语的人,所以请原谅任何翻译错误。

I'm not really having a coding problem. 我真的没有编码问题。 It's more of a conceptual question. 这更像是一个概念性问题。

I wrote two times the same piece of code translating an image into a list of RGB values. 我写了两次相同的代码片段,将图像转换为RGB值列表。 (1 combination of 3 values for each pixel). (每个像素的3个值的1个组合)。

I wrote the code first in VB.net using: 我首先在VB.net中使用以下代码编写代码:

Dim bmp As New Bitmap(File)
For x As Integer = 0 To w - 1 
    For y As Integer = 0 To h - 1
        Dim c As Color = bmp.GetPixel(x, y)
        Dim Red as integer = c.R
        Dim Green as integer = c.G
        Dim Blue as integer = c.B
    Next y
next x

Afterwards I wrote the following in Java: 之后我在Java中写了以下内容:

BufferedImage image = ImageIO.read(new File(File))
for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
        int pixel = image.getRGB(i,j);
        int Red = ((pixel >> 16) & 0xff);
        int Green = ((pixel >> 8) & 0xff);
        int Blue = ((pixel) & 0xff);
    }
}

My expectation would be to get the same values from both pieces of code, since they use the same image. 我的期望是从两段代码中获得相同的值,因为它们使用相同的图像。 I tried it on an image (270x320) which was a photograph (so a full spectrum of colors). 我在一张图片(270x320)上试了一下,这是一张照片(所以颜色都很全)。 To my surprise I saw there where small differences in the RGB values between the VB.net and Java codes. 令我惊讶的是,我看到VB.net和Java代码之间的RGB值存在细微差别。

If I compare the java(red)'s versus the VB.net(red)'s, the java(green)'s versus the VB.net(green)'s and the java(blue)'s versus the VB.net(blue)'s I compare 270x320x3 = 259.2k combinations. 如果我将java(红色)与VB.net(红色)的比较,java(绿色)与VB.net(绿色)和java(蓝色)与VB相比较。 net(blue)我比较270x320x3 = 259.2k组合。 The differences between the integers gotten from the VB.net and from the Java code are as followed: 从VB.net和Java代码获得的整数之间的差异如下:

  • No difference: 250178 (96.5%) 没有区别:250178(96.5%)
  • One difference: 7426 (2.9%) 一个区别:7426(2.9%)
  • Two difference: 1582 (0.6%) 两个区别:1582(0.6%)
  • Three difference: 14 (0.0%) 三个区别:14(0.0%)
  • Four or more diff.: 0 (0.0%) 四个或更多差异:0(0.0%)

Can anybody explain to me where this difference comes from? 任何人都可以向我解释这种差异来自哪里? Has it to do with the way of reading the colors, the way of buffering the image, or with something like anti-aliasing? 是否与阅读颜色的方式,缓冲图像的方式或抗锯齿之类的东西有关?

Really curious what the reason is, thx in advance 真的好奇是什么原因,thx提前

As mentioned by others, the difference is caused by JPEG's lossy compression. 正如其他人所提到的,差异是由JPEG的有损压缩引起的

You should be testing these methods with a lossless format. 您应该使用无损格式测试这些方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM