converting pixel data to image in java -


hi have data of image of size 640 * 480 pixels, data in format of 0s , 1s, in txt file. therefore there 640*480=307200 characters (0s , 1s) in text file. catch 0 means there nothing in original image (say black background) , 1 means there (say user standing , pertaining user blob) , hence not mistaken rgb or byte data.

i need read , convert image of size 640*480 pixels in java,where pixels indicated 0 may set 1 color (say black) , 1 other (say white).
how do it??? help.

first, need read in. if know it's width, can this:

bufferedreader in = new bufferedreader(new filereader("myfile.txt")); boolean[][] mask = new boolean[640][480]; int = -1; int count = 0; while((i = in.read()) !- -1) {     int x = count % 640;     int y = count / 640;     mask[x][y] = (i == '1');     count++; } 

then can paint this

paint(graphics g) {     g.setcolor(color.black);     g.drawrect(0,0,640,480); // draw black background      // mask white     g.setcolor(color.white);     for(int x = 0; x < 640); x++) {         for(int y = 0; y < 480); y++) {             if(mask[x][y]) g.drawrect(x,y,1,1);         }     } } 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -