Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!