2017-06-29 90 views
0

使用JColorChooser的圖像顏色我怎麼可以在Java
圖片使用JColorChooser的這樣 Image 1

圖片2
Image 2如何更改在Java中

File input = new File("dprocessing.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() * 0.299); 
    int green = (int)(c.getGreen() * 0.587); 
    int blue = (int)(c.getBlue() *0.114); 
    Color newColor = new Color(red+green+blue,red+green+blue,red+green+blue); 

    image.setRGB(j,i,newColor.getRGB()); 
    } 
} 

File ouptut = new File("new_Image.jpg"); 
ImageIO.write(image, "jpg", ouptut); 

改變圖像色彩任何幫助將不勝感激...

+3

哪裏是你的代碼? –

+0

對不起,先生,我是新來的,我不能上傳代碼,它說你需要至少10個聲望 – shahzaib

+0

你可以複製並粘貼到你的問題 –

回答

0

你可以溶膠這已經通過其更改爲這樣:

File input = new File("dprocessing.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() * 0.299); 
      int green = (int)(c.getGreen() * 0.587); 
      int blue = (int)(c.getBlue() *0.114); 
      if(c.getRed()>200&&c.getGreen()>200&&c.getBlue()<100){ //this is to make sure that the pixel is some form of yellow. if it is yellow, change it to purple. if it isn't keep the color the same 
       Color newColor = new Color(red,green,blue); //before you were making every field the sum of all 3 colors, I don't know why 
       image.setRGB(j,i,newColor.getRGB()); 
      } 
      else{ 
       image.setRGB(j,i,c.getRGB()); 
      } 

     } 
    } 

    File ouptut = new File("new_Image.jpg"); 
    ImageIO.write(image, "jpg", ouptut); 

讓我知道,如果這對你的作品

+0

不,這也給了相同的結果 – shahzaib

+0

真的嗎?我認爲它應該起作用,或者至少輸出與第一個不同的圖像。你重新編譯了這個項目嗎? –

+0

是的輸出是有點不同,但不是我想要的.... – shahzaib