开发者

Create bitmap or image row by row? or create bitmap/image from 2D array in Java

This amounts to a pretty basic programming question, but essentially I am creating an array of 1s and 0s that I want to represent a single row of black (1) or white (0) pixels. Here is the code I have,

private void runSim(){
        for(int j = 0; j< iterations; j++){
        for(int i = 0; i< rowLength; i++){
            newRow[i] = getNewCell(i);
        }
        oldRow = newRow;
        //draw new row
        printIteration();
    }
}
oldRow is an array of int values (all 0's and 1's) that represents a row of pixels I want to add to the bottom of the bitmap image. Ideally, there is some way to add pixels row wise like this.If not, then I can create a 2D array of these int values instead, but I still don't know how 开发者_开发知识库to get them to written into an image as black and white pixels. Can anyone help me with this, or get me pointed in the right direction? please forgive this elementary question, and thanks in advance for any help.


Seems to me you could use an ArrayList of BitSet classes.

http://download.oracle.com/javase/6/docs/api/java/util/BitSet.html

As far as writing into an image, take a look at the java BufferedImage class.


A pointer: Start with the clean slate of a VolatileImage in an extended JPanel. Override its paintComponent() method, using Graphics2D to paint the image off-the-screen, and draw() the resulting image on the Graphics object sent to paintComponent() as argument. Use your 1-D or 2-D array of pixels in the paintOffScreen(Graphics2D) method to update the VolatileImage as and when required. Hope this helps, - M.S.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜