Trying to make a photo filter's effects cumulative on the photo-java swing -
basically have made interface displays picture , has multiple jsliders. each 1 has different function such blur, brighten, , saturate. have implemented sliders in such way override statechanged method when adding new slider. works fine when sliders individually, changes original picture once use different slider. want make picture accumulates filters on photo. suggestions? here example of 1 of sliders.
brightslider.addchangelistener(new changelistener() { @override public void statechanged(changeevent e) { jslider source = (jslider) e.getsource(); double scalevalue = source.getvalue() / 100.0; picture newpic = new pictureimpl(picture.getwidth(), picture.getheight()); //picture newpic = picture; pixel zeropixel = new colorpixel(0, 0, 0); pixel p; (int = 0; < picture.getwidth(); i++) { (int j = 0; j < picture.getheight(); j++) { newpic.setpixel(i, j, zeropixel); } } (int = 0; < picture.getwidth(); i++) { (int j = 0; j < picture.getheight(); j++) { if (scalevalue > 0) { p = picture.getpixel(i, j).lighten(scalevalue); newpic.setpixel(i, j, p); } else if (scalevalue < 0) { p = picture.getpixel(i, j).darken(scalevalue); newpic.setpixel(i, j, p); } } } setpic(newpic); picture_view.setpicture(newpic.createobservable()); } });
as shown in image processing java 2d, can create map<string, bufferedimageop>
holds concrete instances of bufferedimageop
interface.
map<string, bufferedimageop> ops = new treemap<string, bufferedimageop>(); colorspace cs = colorspace.getinstance(colorspace.cs_gray); ops.put("gray", new colorconvertop(cs, null)); …
add map
key set jcombobox
.
final jcombobox opbox = new jcombobox(); (string key : ops.keyset()) { opbox.additem(key); }
in combo's handler, invoke image operation's filter()
method on target bufferedimage
.
string key = (string) opbox.getselecteditem(); bufferedimageop op = ops.get(key); bufferedimage = op.filter(bufferedimage, null);
the image below illustrates "threshold 64" followed "invert". imagedicer
complete example.
Comments
Post a Comment