Converting Red, Green and Blue to RGB

隐身守侯 提交于 2019-12-13 09:22:04

问题


first I get Red, Green and Blue value from the following code,

  BufferedImage  image; 
  File input = new File("digital_image_processing.jpg");
     image = ImageIO.read(input);
     width = image.getWidth();
     height = image.getHeight();
      for(int i=0; i<height; i++){
        for(int j=0; j<width; j++){
           Color c = new Color(image.getRGB(j, i));
           int red = (int)c.getRed();
           int green = (int)c.getGreen() ;
           int blue = (int)c.getBlue() ;

Here After Getting the Red, Green and Blue value from getRGB(), I want to Do some modification with the Red, Green and Blue value then again I want to convert it to same RGB value, or create a new 2d array RGB for the combined Red, Green and blue value. How to do it?? Any Guess.. Pls. Help


回答1:


Abdul's answer is great, but it can be really slow when creating new objects of type 'Color' thousands of times. The simplest way would be:

int rgb = (red << 16 | green << 8 | blue)



回答2:


The simplest way to do it will be:

new Color(red, green, blue).getRGB();  

Also, as I see you are into Image Processing & Graphics, I suggest you my blog where I have written quite a few articles on the topic.



来源:https://stackoverflow.com/questions/24594046/converting-red-green-and-blue-to-rgb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!