2013-04-05 6 views
0

Je veux convertir un graphique linéaire que j'ai fait avec AChartEngine lib en bitmap.Comment devrais-je faire? Je n'ai pas trouvé sur le net tout ce qui peut aider. La méthode toBitmap() est-elle adaptée? Si oui, comment l'utiliser?Comment convertir un graphique AChartEngine en bitmap

Mise à jour: Je utilisé cette méthode:

public static Bitmap loadBitmapFromView(View v) { 
v.setDrawingCacheEnabled(true); 
v.layout(0,0,800,600); 
v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 
v.buildDrawingCache(); 
v.getDrawingCache(); 
Bitmap bmp = Bitmap.createBitmap(800,600, Bitmap.Config.ARGB_8888); 
v.setDrawingCacheEnabled(false); 
return bmp; } 

et enregistré le résultat dans un fichier .png, mais tout ce que je suis est un fichier vide!

Répondre

0

toBitmap() semble toujours renvoyer une valeur nulle.

Essayez ceci:

  //Get the graphical view 
      GraphicalView v = ChartFactory.getLineChartView(context, 
          buildDataset(titles, x, values), renderer); 

      //Enable the cache 
      v.setDrawingCacheEnabled(true); 

      //Set the layout manually to 800*600 
      v.layout(0, 0, 800, 600); 

      //Set the quality to high 
      v.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); 

      //Build the cache, get the bitmap and close the cache 
      v.buildDrawingCache(true); 
      Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); 
      v.setDrawingCacheEnabled(false); 
+1

je viens d'essayer cela, il renvoie null trop – user2137817

0

Un peu plus tard, mais ce que je l'ai fait pour créer un fichier JPG (via Bitmap) à partir d'un GraphicalView:

Bitmap bmp = Bitmap.createBitmap(600, 1000, Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(bmp); 
graphicalView.draw(canvas); 

FileOutputStream out = new FileOutputStream(filename); 
bmp.compress(Bitmap.CompressFormat.JPEG, 97, out); 
out.close();