I have a Bitmap Image loaded to a 2D Array. Now I want to detect the outer edge pixels of the bitmap for efficient pixel-exact-collison-detection. The red pixel represent the edge which should be detected.
Is there a simple algorithm to achieve this result?
I've written a code to display a array of pixels.
I'm quite new to programming and would like to learn how to code more efficient.
So my questions is, if there is a much faster way to do this, cause i'm about to programm a little game upon this function.
final int QUANT = 4; // size of 'game pixels'
void setup(){
size(200,200);
background(255);
// defines the bitmap image that should be displayed
byte[][] bild =
{{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0},
{0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1},
{0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0},
{0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0},
{1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
// calls the function to display the image at x=1,y=3
draw_img(1,3,bild);
}
void draw_img(int _x,int _y, byte[][] img){
// following loops go through every pixel of the image