android - How can i implement seek bar to change contrast -


i trying implement seek bar change contrast of image in android. me implement please.there other options image processing ? know solution please me

thanks in advance.

code:

    public class mainactivity extends actionbaractivity {     imageview imviewandroid;     private seekbar seekbar;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         seekbar = (seekbar) findviewbyid(r.id.seekbar);         imviewandroid = (imageview) findviewbyid(r.id.imviewandroid);           seekbar.setonseekbarchangelistener(new seekbar.onseekbarchangelistener() {             @override             public void onprogresschanged(seekbar seekbar, int i, boolean b) {              }              @override             public void onstarttrackingtouch(seekbar seekbar) {                 imviewandroid.setimagebitmap(takecontrast(bitmapfactory.decoderesource(getresources(), r.drawable.dicom), 100));             }              @override             public void onstoptrackingtouch(seekbar seekbar) {              }         });      }   public  bitmap takecontrast(bitmap src, double value) {         // src image size         int width = src.getwidth();         int height = src.getheight();         // create output bitmap original size         bitmap bmout = bitmap.createbitmap(width, height, src.getconfig());         // color information         int a, r, g, b;         int pixel;         // contrast value         double contrast = math.pow((100 + value) / 100, 2);          // scan through pixels         for(int x = 0; x < width; ++x) {             for(int y = 0; y < height; ++y) {                 // pixel color                 pixel = src.getpixel(x, y);                 = color.alpha(pixel);                 // apply filter contrast every channel r, g, b                 r = color.red(pixel);                 r = (int)(((((r / 255.0) - 0.5) * contrast) + 0.5) * 255.0);                 if(r < 0) { r = 0; }                 else if(r > 255) { r = 255; }                  g = color.red(pixel);                 g = (int)(((((g / 255.0) - 0.5) * contrast) + 0.5) * 255.0);                 if(g < 0) { g = 0; }                 else if(g > 255) { g = 255; }                  b = color.red(pixel);                 b = (int)(((((b / 255.0) - 0.5) * contrast) + 0.5) * 255.0);                 if(b < 0) { b = 0; }                 else if(b > 255) { b = 255; }                  // set new pixel color output bitmap                 bmout.setpixel(x, y, color.argb(a, r, g, b));             }         }          // return final image         return bmout;     } 

  1. you call function change contrast in wrong place should here

    @override public void onprogresschanged(seekbar seekbar, int progress, boolean b) {     // call method here, default progress <0, 100> } 
  2. you use slow function change contrast. there plenty answers on stackoverflow, have @ this answer. search before ask.

look @ full implementation on github.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -