Sprawa wydaje mi się jest dość prosta. Postanowiłem napisać małą aplikację która konwertowała by wyłączenie kolory na zdjęciu na model RGB za pomocą suwaków tak jak wygląda to w aplikacji Photoshop. Nie mogę tylko dość do tego jak zmodyfikować działanie suwaka tak aby modyfikował kolor np nie paneli tylko zdjęcie. Albo aplikacja jest od podstaw źle napisana, albo jest jakiś fragment który przeoczyłem. Kolor jest pobierany zapisywany do zmiennych, ale nie jest konwertowany.
Docelowo aplikacja ma byc dedykowana na systemy Android , ale na razie wolałem ją stworzyć w prostszy sposób.
KOD:
package graphic_application_elements_test;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class ConverttoRed {
static BufferedImage imagecolor = null;
static File f = null;
static JFrame frame = new JFrame("Color Slider");
static JPanel panel = new JPanel();
static JPanel panelRGB = new JPanel();
static JPanel panelSliders = new JPanel();
static JSlider sliderRed = new JSlider();
static JSlider sliderGreen = new JSlider();
static JSlider sliderBlue = new JSlider();
static Icon pic = new ImageIcon("E:\\Pics\\little_computer_guy.jpg");
static JLabel labelimg = new JLabel("image", pic, JLabel.LEFT);
public static void main(String[] args){
sliderRed.setMinimum(0);
sliderRed.setMaximum(255);
panelRGB.add(sliderRed);
panelRGB.add(sliderGreen);
panelRGB.add(sliderBlue);
panelSliders.add(panelRGB);
panel.add(panelSliders);
panel.add(labelimg);
frame.setContentPane(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(true);
try{
f = new File("little_computer_guy.jpg");
imagecolor = ImageIO.read(f);
}catch(IOException e){
System.out.println(e);
}
class SliderListenerRGB implements ChangeListener{
public void stateChanged(ChangeEvent e){
//getting a primary values from slider
int red = sliderRed.getValue();
int green = sliderGreen.getValue();
int blue = sliderBlue.getValue();
System.out.print(green);
//get width and height
int width = imagecolor.getWidth();
int height = imagecolor.getHeight();
//convert to color
for( int y = 0 ; y < height ; y++){
for( int x = 0 ; x < width ; x++){
int p = imagecolor.getRGB(red, green);
int a = (p >> 24)&0xff;
int g = (p >> green)&0xff;
p = (a << 24 | 0 << 16 | g << green) | 0;
imagecolor.setRGB(x,y,p);
}
}
/* Icon icon2 = new ImageIcon(imagecolor);
JLabel labelimg = new JLabel("image", icon2, JLabel.LEFT);*/
}
}
try{
f = new File("E:\\Pics\\little_computer_guy_2.jpg");
ImageIO.write(imagecolor, "png", f);
}catch(IOException a){
System.out.println(a);
}
}
}