1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| package com.formattion.Binarisation6;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class Main extends Activity {
int width, height;
int[][]matrice = new int[width][height];
int j,k;
int red = 0,green = 0, blue = 0;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bmpOriginal = BitmapFactory.decodeResource(getResources(), R.drawable.bimage1);
height = bmpOriginal.getHeight();
width = bmpOriginal.getWidth();
int a1=(int)((width*height)/9);
int a2=(int)(2*(width*height)/9);
int a3=a2-a1;
int[][]matrice = new int[width][height];
int[] pix =new int [width * height];
int[] valpix =new int [width * height];
int[] valpix1 =new int [a1];
int[] valpix2 =new int [a2-a1];
//le tableau pix contient la couleur de chaque pixel
bmpOriginal.getPixels(pix, 0, width, 0, 0, width, height);
for(int i=0;i<width * height;i++)
{
red = (pix[i] >> 16)& 0xff ;
green = (pix[i] >> 8)& 0xff;
blue = pix[i] & 0xff;
valpix[i]=(int)(red+green+blue)/3;
}
///////////////////////////////////Decouper le tableau en 9 tableaux////////////////////////////
int g=0;
for(int k=0;k<a1;k++)
{ valpix1[g]=valpix[k];
g++;
}
g=0;
for(int k=a1;k<a2;k++)
{ valpix2[g]=valpix[k];
g++;
}
StringBuffer str = new StringBuffer();
for(int h=a1;h<a2-1;h++) {
str.append(Integer.toString(valpix2[h]));
}
TextView tv=new TextView(this);
tv.setText("tab= "+str.toString());
setContentView(tv);
} |
Partager