Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda