Bonjour,
Pour un projet personnel je dois manipuler des images qui sont pour l'instant des images testes.
En les manipulant je passe par l'objet Bitmap. Néanmoins quand je tente d'accéder au propriété de l'image j'ai une largeur qui est différente de la largeur de l'image.
Je dois commettre une erreur mais où?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package app.main.activities; import container.picture.MyCanvasManager; public class Launcher extends Activity { private MyCanvasManager pictureManager = null; private Button analyseButton = null; private ImageView canvas = null; private void addInterfaceBehavior(int drawableId){ canvas = (ImageView)findViewById(R.id.ImageView01); if(canvas == null) finish(); pictureManager = new MyCanvasManager(getResources().getDrawable(drawableId), handler); canvas.setScaleType(ImageView.ScaleType.FIT_CENTER); canvas.setImageResource(drawableId); analyseButton = (Button)findViewById(R.id.Button01); analyseButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub new Thread(new Runnable() { public void run() { // Instructions consommatrices en temps analysePicture(); } }).start(); } }); } // Define the Handler that receives messages from the thread and update the progress final Handler handler = new Handler() { public void handleMessage(Message msg) { switch(MainActiviHandlerMsg.values()[msg.what]){ case PICTURE_IN_BLACK_AND_WHITE: ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); canvas.setColorFilter(new ColorMatrixColorFilter(cm)); canvas.invalidate(); break; default:return; } } }; private void analysePicture() { // TODO Auto-generated method stub if(pictureManager != null){ synchronized(canvas){ pictureManager.launchAnalysis(); } //analyseButton.setEnabled(false); } } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addInterfaceBehavior(R.drawable.sample_10); } }Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public class MyCanvasManager{ private Bitmap picture = null; private Handler aHandler = null; private static final float MIN_X_CIE_VAL = 0.5125f; private static final float MAX_X_CIE_VAL = 0.6915f; private static final float MIN_Y_CIE_VAL = 0.3083f; private static final float MAX_Y_CIE_VAL = 0.4866f; public MyCanvasManager(Drawable img,Handler h){ //this.canvas = imV; BitmapDrawable bd = (BitmapDrawable)img; picture = bd.getBitmap(); this.aHandler = h; } public void launchAnalysis(){ int w_picture = picture.getWidth(); int h_picture = picture.getHeight(); int[] pixels = new int[w_picture * h_picture]; picture.getPixels(pixels, 0, w_picture, 0, 0, w_picture, h_picture); } }
Je travaille avec la 2.1
Partager