2016-11-01 2 views
0

Ich entwickle eine App, die Bilder mit Intents machen und speichern kann. Nach 10 bis 15 Bildern wird die App sehr langsam. Code zur Bildaufnahme ist wie folgt:Warum Android-App langsam wird

private void capturePhoto() { 

      File root = new File(Environment.getExternalStorageDirectory(), "Feedback"); 
      if (!root.exists()) { 
       root.mkdirs(); 
      } 
      File file = new File(root, Constants.PROFILE_IMAGE_NAME + ".jpeg"); 
      Uri outputFileUri = Uri.fromFile(file); 


      Intent photoPickerIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
      photoPickerIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); 
      photoPickerIntent.putExtra("return-data", true); 
      photoPickerIntent.putExtra("android.intent.extras.CAMERA_FACING", 1); 
      startActivityForResult(photoPickerIntent, requestCode); 


     } 
     @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
      super.onActivityResult(requestCode, resultCode, data); 
      if (this.requestCode == requestCode && resultCode == RESULT_OK) { 


       File file = new File(root, Constants.PROFILE_IMAGE_NAME+".jpeg"); 
       checkFlowIdisPresent(file); 

        displayPic(); 


      } 
     } 
private void displayPic() { 

     String filePath = Environment.getExternalStorageDirectory() 
       .getAbsolutePath() + File.separator + "/Feedback/" + Constants.PROFILE_IMAGE_NAME + ".jpeg"; 
     // Bitmap bmp = BitmapFactory.decodeFile(filePath); 
     //Bitmap scaled = Bitmap.createScaledBitmap(bmp, 300, 300, true); 

     File imgFile = new File(filePath); 
     Bitmap bmp = decodeFile(imgFile); 


     if (imgFile.exists()) { 

      dispProfilePic.setImageBitmap(bmp); 
     } else { 

      dispProfilePic.setBackgroundResource(R.drawable.user_image); 

     } 
    } 

Edited DisplayPic() -Methode oben

gezeigt
+0

Sie zeigen alle Bilder zusammen in 'ListView' oder etwas? – Max

+0

meine App im Grunde Feedback-App. werde nicht in Listenansicht angezeigt. werde gerade in einer Bildansicht angezeigt. Nach 10 bis 15 Feedback wird es langsam –

+0

Vielleicht, weil Sie alle Bilder anzeigen, sollten Sie das letzte Bild schließen, wenn ein anderer genommen wird – GlacialMan

Antwort

0

Sie benötigen eine Bildlade Bibliothek verwenden, um die Bilder zu laden.

Glide ist mein Favorit.

seine Einrichtung ist sehr einfach:

put diese n Ihre build.gradle

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
} 

dann Ihre Methode

private void displayPic() { 
    String filePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "/Feedback/" + Constants.PROFILE_IMAGE_NAME + ".jpeg";  
    Glide.with(context).load(filePath).override(300, 300).into(dispProfilePic); 
} 

sein können Sie mehr informatin und Nutzungsdetails here finden.