loadBytes() to read from memory?

loadBytes() loads a file into a byte array. Is it possible to read the real-time processing of an image (or movie) from memory? I am looking to add some glitch to it, and I am looking for a way to do it.

Answers

  • make a call to loadPixels();

    it will copy contents of the frame buffer to an array called pixels[i]

    hope this helps

  • edited January 2014 Answer ✓

    Like zumbaree wrote, you can use loadPixels()/updatePixels() or copy() (nice for glitches, shown in the example code below) or, in case you want better performance, make use of Processings PShader class.

    Example code:

    PImage back;
    Glitch[] glitches;
    
    void setup() {
    
        size(800, 800);
        noStroke();
    
        back = loadImage("upload.wikimedia.org/wikipedia/commons/3/3d/FuBK-Testbild.png");
        back.resize(width, height);
    
        glitches = new Glitch[8];
        for(int n = 0; n < glitches.length; n++)
            glitches[n] = new Glitch((int)random(height), 0.5 + random(4), 4 + (int)random(42), 2 + random(6));
    
    }
    
    void draw() {
    
        background(back);
    
        fill(#000000, 10);
        for(Glitch glitch : glitches)
            glitch.render();
    
        fill(#ffffff);
        text("FPS " + frameRate, 10, 10 + textAscent());
    
    }
    
    class Glitch {
    
        float pos;
        float speed;
        int size;
        float strenght;
    
        Glitch(float pos, float speed, int size, float strenght) {
            this.pos = pos;
            this.speed = speed;
            this.size = size;
            this.strenght = strenght;
        }
    
        void render() {
            pos += speed;
            if(pos > height)
                pos = 0;
            int y = (int)pos;
            for(int n = 0; n < size; n++) {
                int offset = (int)((0.5 - random(1.0)) * strenght);
                copy(0, y + n, width, 10, (int)((0.5 - random(1.0)) * strenght), y + n + (offset >> 1), width, 10);
                rect(0, y + n, width, 10);
            }
        }
    
    }
    

    Since the text processor hates links (or likes them too much), please insert h t t p : / / (without the spaces) before upload.wikimedia.org.

Sign In or Register to comment.