将红,绿和蓝转换为RGB [英] Converting Red, Green and Blue to RGB

查看:196
本文介绍了将红,绿和蓝转换为RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我从以下代码中获得红色,绿色和蓝色值:

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() ;

这里在从getRGB()获得红色,绿色和蓝色值后,我想做一些修改用红色,绿色和蓝色值,然后再次我想将其转换为相同的RGB值,或创建一个新的2d阵列RGB的红色,绿色和蓝色的值组合。怎么做??
任何猜测..帮助

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

推荐答案

Abdul的答案是很好的,但是当创建'Color'类型的新对象时,最简单的方法是:

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)

这篇关于将红,绿和蓝转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆