BufferedImage.getRGB()的准确性

时间:2014-07-07 07:46:01

标签: java image-processing rgb bufferedimage

我编写了一个可以从jpg文件中读取rgb值的程序,但是当我用纯色测试时,我得到的rgb结果稍有不准确。有没有人知道我的代码是否是不正确的java?

RGB

red=64 green=0 blue=128

RESULT

red=65 green=0 blue=128

CODE

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.ArrayList;
import javax.imageio.*;


public class Program {
    public int[][] rgbValues;
    public File imagePath = new File("src/image3.jpg");
    public BufferedImage image;

    public Program() throws IOException{
        image = ImageIO.read(imagePath);
        rgbValues = new int[image.getWidth()][image.getHeight()];
    }
    public void run() throws IOException{
        getData();
        analyzeData();

    }
    private void getData() throws IOException{      
        for (int y = 0; y < image.getHeight(); y++){
            for (int x = 0; x < image.getWidth(); x++){
                rgbValues[y][x] = image.getRGB(x, y);
            }

        }
    }
    private void analyzeData() throws IOException{
        boolean f = image.getAlphaRaster() != null;
        Color color = new Color(rgbValues[10][10], f);
        System.out.println(color.getRed());
        System.out.println(color.getGreen());
        System.out.println(color.getBlue());

    }

}

1 个答案:

答案 0 :(得分:0)

代码看似正确并且结果也是如此,Paint说图像也是(65,0,128)

相关问题