bufferedimage - Image converter java -


i'm working image processing, , have question.

i want read image project, , convert image gray. i'm trying conversion function rgb2gray, still not working.

import java.awt.color; import java.awt.component; import java.awt.dimension; import java.awt.graphics; import java.awt.event.windowadapter; import java.awt.event.windowevent; import java.awt.image.bufferedimage; import java.io.file; import java.io.ioexception;  import javax.imageio.imageio; import javax.swing.jframe;  public class imagetesting extends component {     private static int[] pixel;     private static bufferedimage b;      bufferedimage image;      public void paint(graphics g) {         g.drawimage(image, 0, 0, null);     }      public imagetesting() {         try {             image = imageio.read(new file("teste.jpg"));         } catch (ioexception e) {         }     }      public dimension getpreferredsize() {         if (image == null) {             return new dimension(400, 400);         } else {             return new dimension(image.getwidth(null), image.getheight(null));         }     }      public static bufferedimage rgb2gray(bufferedimage bi) {         int heightlimit = bi.getheight();         int widthlimit = bi.gettilewidth();         bufferedimage converted = new bufferedimage(widthlimit, heightlimit, bufferedimage.type_byte_gray);         (int height = 0; height < heightlimit; height++) {             (int width = 0; width < widthlimit; width++) {                 color c = new color(bi.getrgb(width, height) & 0x00fffff);                 int newred = (int) ((0.2989f * c.getred()) * 2);// 0.2989f//multiplicr po 2                 int newgreen = (int) ((0.5870f * c.getgreen()) * 2);// 0.5870f                 int newblue = (int) ((0.1140f * c.getblue()) * 2);                 int rooffset = newred + newgreen + newblue;                 converted.setrgb(width, height, rooffset);             }         }         return converted;     }      /**      * @param args command line arguments      */     public static void main(string[] args) throws ioexception {         // todo code application logic here         jframe f = new jframe("load image sample");         jframe g = new jframe("image rgb");         f.addwindowlistener(new windowadapter() {             public void windowclosing(windowevent e) {                 system.exit(0);             }         });         g.addwindowlistener(new windowadapter() {             public void windowclosing(windowevent e) {                 system.exit(0);             }         });         f.add(new imagetesting());         f.pack();         f.setvisible(true);         g.add(new imagetesting());         rgb2gray(b);     } } 

when run program,these errors appear.

if me, apreciate. thanks

edit: managed solve problem,but question came up. continue work, want find 10 brilhants points in resultant image, , return image black color in index's have value 0, , white color in index's have value 1,but @ point don't understand best way work out steps.

it seems there's wrong main() method, isn't it? create 2 identical jframe instances, add imagetesting components display original image. , when running rgb2gray @ end, result sent nowhere.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -