2010-08-13 5 views
1

amis,qui est la méthode appropriée pour recliquer le bitmap?

J'ai une page sur laquelle j'affiche l'image de la galerie puis j'ai le bouton de la page suivante pour passer à l'activité suivante sur ce bouton J'utilise clearBitmap(); pour libérer de la mémoire utilisée par celui-ci.

bitmap bitmap privé;

oncreate() 
{ 

_image = (ImageView)findViewById(R.id.MyImage); 

_path = getRealPathFromURI(_data.getData()); 


      BitmapFactory.Options options = new BitmapFactory.Options(); 


      options.inSampleSize = 2; 

      bitmap = BitmapFactory.decodeFile(_path, options); 

_image.setImageBitmap(bitmap); 


next.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View view) { 

      Intent myIntent = new Intent(UploadImageOnly.this, ImageGallery.class); 

         startActivity(myIntent); 

clearBitmap(); 




} 

qui me donne l'erreur logcat

08-13 12:07:07.649: ERROR/AndroidRuntime(753): Uncaught handler: thread main exiting due to uncaught exception 
08-13 12:07:07.869: ERROR/AndroidRuntime(753): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap [email protected] 
08-13 12:07:07.869: ERROR/AndroidRuntime(753):  at android.graphics.Canvas.throwIfRecycled(Canvas.java:955) 
08-13 12:07:07.869: ERROR/AndroidRuntime(753):  at android.graphics.Canvas.drawBitmap(Canvas.java:1044) 
08-13 12:07:07.869: ERROR/AndroidRuntime(753):  at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:323) 
08-13 12:07:07.869: ERROR/AndroidRuntime(753):  at android.widget.ImageView.onDraw(ImageView.java:845) 
08-13 12:07:07.869: ERROR/AndroidRuntime(753):  at android.view.View.draw(View.java:6535) 

Code

public void clearBitmap() { 

     try{ 
      if(bitmap!=null && !bitmap.isRecycled()){ 
        bitmap.recycle(); 
        bitmap = null; 
      } 
      }catch(Throwable e){ 
        System.out.println(e.getMessage()); 
        e.printStackTrace(); 
      } 

      System.gc(); 

     } 

Répondre

0

laisser le garbage collector gérer. Vous n'avez pas besoin d'utiliser Bitmap#recycle() dans votre cas ou dans un cas normal vraiment.

+0

ok si je ne l'ouvre pas différentes images de la galerie encore et encore ... je reçois un crash hors de l'exception de la mémoire. la mémoire de version est donc nécessaire dans ce cas. – UMAR

+0

Ensuite, vous gardez des références à vos bitmaps et ils ne sont pas récupérés. – Qberticus

+0

alors quelle est la procédure pour les tuer tous? – UMAR

Questions connexes