Bonjour tout le monde.

J'ai créer un objet qui affiche des carrés à l'écran. Le code fonctionne parfaitement.

De là je voudrais mettre le carré créer dans un fichier .jpg vide mais je n'y arrive pas.

Voici la classe qui fait les carrés :
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
public class Dessine_Carre extends DessinneForme implements Element
{
  protected float coint_inf_x;
  protected float coint_inf_y;
  protected Paint combre;
  protected boolean ombre = false;
  public Dessine_Carre(Context context, double posx, double posy,double pbx,double pby, int couleur,int taille) 
  {
    super(context, (float)posx, (float)posy, couleur,taille);
	this.coint_inf_x =(float)pbx;
	this.coint_inf_y =(float)pby;
 
 
  }
  public Dessine_Carre(Context context, double posx, double posy,double pbx,double pby, int couleur,int taille,int combre) 
  {
    super(context, (float)posx, (float)posy, couleur,taille);
	this.coint_inf_x =(float)pbx;
	this.coint_inf_y =(float)pby;
	this.combre = new Paint();
	this.combre.setColor(combre);
	this.ombre=true;
  }
   protected void onDraw(Canvas canvas) 
  {
	if(this.ombre)
	{
	  this.combre.setStyle(Paint.Style.STROKE);
	  this.combre.setStrokeWidth(7);
	  canvas.drawRect(this.d_x+2,this.d_y+2,this.coint_inf_x ,this.coint_inf_y, this.combre);
	}
	if(!this.ombre)this.paint.setStyle(Paint.Style.STROKE);
	canvas.drawRect(this.d_x,this.d_y,this.coint_inf_x ,this.coint_inf_y, this.paint);
    invalidate();
  }
  protected void CHANGE_SECOND_POINT(int ne_posx,int ne_posy)
  {
    this.coint_inf_x=ne_posx;
	this.coint_inf_x=ne_posy;	  
  }
  public  float getFinx()
  {
    return this.coint_inf_x;
  }
  public float getFiny()
  {
    return this.coint_inf_y;
  }
  public  float getFinOmbrex()
  {
    return this.coint_inf_x+4;//7taille-2x-1px=4
  }
  public float getFinyOmbre()
  {
    return this.coint_inf_y+4;//7taille-2x-1px=4
  }
  public float getLargeur()
  {
    return this.coint_inf_x - this.d_x;
  }
  public float getHauteur()
  {
	  return this.coint_inf_y - this.d_y;  
  }
 
public List<Chunk> getChunks() {
	// TODO Auto-generated method stub
	return null;
}
public boolean isContent() {
	// TODO Auto-generated method stub
	return false;
}
public boolean isNestable() {
	// TODO Auto-generated method stub
	return false;
}
public boolean process(ElementListener arg0) {
	// TODO Auto-generated method stub
	return false;
}
public int type() {
	// TODO Auto-generated method stub
	return 0;
}
}
Fonctionne sans problème.


Voici le code de la fonction que je voudrais utiliser pour mettre le carré dans un jpg.

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
 
public void INSET_INTO(Dessine_Carre element)//element contient un carré déjà dessiné
	{
 
          //Chargement du fichier jpg de base
	  Bitmap img_toile = BitmapFactory.decodeFile(this.m_PathComplet);
 
          //Création d'un bitmap, que serra utiliser comme une toile  vide
	  Bitmap btimap_vide = Bitmap.createBitmap(img_toile.getWidth(),img_toile.getHeight(),Config.ARGB_8888);
     Canvas canvas = new Canvas (btimap_vide);	
 
      //On dessine l'image bitmap de base dans la toile
      canvas.drawBitmap(img_toile ,0f,0f, null);
 
      //Conversion de Dessine_Carre en bitmap
      element.buildDrawingCache(true);
      Bitmap bitmap_element=Bitmap.createBitmap(element.getDrawingCache());//BUG
 
       //On dessine le carré dans la toile
      canvas.drawBitmap(bitmap_element,0f,0f, null);
 
	  FileOutputStream resultat;
	  try 
	  {
                //Création d'un nouveau fichier jpg
		resultat = new FileOutputStream(this.m_Path + "autre.JPG");
		btimap_vide.compress(CompressFormat.JPEG, 100, resultat);
	  	resultat.close();
 
	  } 
	  catch (FileNotFoundException e) 
	  {
		// TODO Auto-generated catch block
		e.printStackTrace();
	  } 
	  catch (IOException e)
	  {
		// TODO Auto-generated catch block
		e.printStackTrace();
	  }	      		  
    }
Le problème surviens à la ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
      Bitmap bitmap_element=Bitmap.createBitmap(element.getDrawingCache());
Car element.getDrawingCache() retourne null.

Merci de m'avoir lu.