mercredi 25 février 2015

Give Border To Texture - SetPixel

I'm trying to dynamically add a border to a texture of mine. So far, I have a border at the top, and at the bottom. But struggling to get a left and right border. This is what I have so far:



var i = image;
var pixels : Color[] = i.GetPixels(0, 0, i.width, i.height, 0);
var br : int = 1;

for(var p = 0; p < pixels.Length; p++){

var b : int = 30;

//Bottom
if(p < i.width * b)
pixels[p] = new Color(1,0,0,1);

//Top
if(p > (i.height * i.width) - (i.width * b))
pixels[p] = new Color(1,0,0,1);


//int when a new row of pixels has began
if(p > i.width * br)
br++;

}


The pixels are read from bottom left, to top right. I just can't seem to get my head around the maths.


Thanks


Aucun commentaire:

Enregistrer un commentaire