Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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. (1 combination of 3 values for each pixel).

I wrote the code first in VB.net using:

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:

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). To my surprise I saw there where small differences in the RGB values between the VB.net and Java codes.

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. The differences between the integers gotten from the VB.net and from the Java code are as followed:

  • No difference: 250178 (96.5%)
  • One difference: 7426 (2.9%)
  • Two difference: 1582 (0.6%)
  • Three difference: 14 (0.0%)
  • Four or more diff.: 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

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

As mentioned by others, the difference is caused by JPEG's lossy compression.

You should be testing these methods with a lossless format.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda