PImage Copy

In my last post, I talked about not being able to get copy working. Well after a couple sleepless days and a LOT of help form my class. (Dave, don’t forget to give them contribution marks). We finally figured it out. Anyhow, I was missing a big concept. Like I stated in my previous post i was using:

this.data.pixels = buildImageObject(obj).pixels;

this changes the way the pixel array is set up. After calling this function every index of the pixel array has “rgba(r,g,b,a)”, so when you go to copy pixels from one index to another and then draw the image using image() you get an error.

Canvas uses a pixel array that holds each color in an array index. So if we refer to the color above, pixels[i] = r, pixels[i+1] =g, pixels[i+2] = b, pixels[i+3] = a. This is a one dimensional array and the size = width*height*4.

The code for this function is a little complicated, it consists of 2 for loops. Changing  the first row is easy. The trick is getting to the next row, by jumping indexes. I think my code still has some bugs. But here is a screen shot:

 

View all of my blogs on Processing.js
View all of my blogs

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s