2012-04-16 2 views
0

Je suis nouveau sur android. J'essaye de faire une sorte de traitement d'image. Mais je reçois ce message "Cette application s'est arrêtée de manière inattendue. Veuillez réessayer.". Veuillez me dire quelle erreur je faisapplication android faisant la force close

package com.imagep.amit; 

import java.io.BufferedOutputStream; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 

import android.app.Activity; 
import android.graphics.Bitmap; 
import android.graphics.Bitmap.CompressFormat; 
import android.graphics.BitmapFactory; 
import android.os.Bundle; 
import android.util.Log; 
import android.widget.ImageView; 

public class ImagepActivity extends Activity { 
    /** Called when the activity is first created. */ 

    Bitmap myBitmap; 
    ImageView myImageView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     String imageFileName= "/sdcard/test_vga.jpg"; 
     File imageFile= new File(imageFileName); 
     if (imageFile.exists()) { 
      // Load the image from file 
      myBitmap= BitmapFactory.decodeFile(imageFileName); 
      // Display the image in the image viewer 
      myImageView= (ImageView)findViewById(R.id.di); 
      if (myImageView!= null) { 
       myImageView.setImageBitmap(myBitmap); 
      } 
     } 
     this.processImage(); 
    } 

    private void processImage() { 
     brighten(50); 
     try { 
      String outputPath= "/test_vga_output.jpg"; 
      int quality = 75; 
      FileOutputStream fileOutStr= new FileOutputStream(outputPath); 
      BufferedOutputStream bufOutStr= new BufferedOutputStream(fileOutStr); 
      myBitmap.compress(CompressFormat.JPEG, quality, bufOutStr); 
      bufOutStr.flush(); 
      bufOutStr.close(); 
     } catch (FileNotFoundException exception) { 
      Log.e("debug_log", exception.toString()); 
     } catch (IOException exception) { 
      Log.e("debug_log", exception.toString()); 
     } 
     myImageView.setImageBitmap(myBitmap); 
    } 

    private void brighten(int i) { 
     int width = myBitmap.getWidth(); 
     int height = myBitmap.getHeight(); 
     int[] pix = new int[width * height]; 
     myBitmap.getPixels(pix, 0, width, 0, 0, width, height); 
     // Apply pixel-by-pixel change 
     int index = 0; 
     for(int y = 0; y < height; y++) { 
      for (int x = 0; x < width; x++) { 
       int r = (pix[index] >> 16) & 0xff; 
       int g = (pix[index] >> 8) & 0xff; 
       int b = pix[index] & 0xff; 
       r = 0; 
       g = 0; 
       b = 0; 
       pix[index++] = 0xff000000| (r << 16) | (g << 8) | b; 
      } // x 
     } // y 
     // TODO Auto-generated method stub 
    } 
} 
} 
+0

Bonjour, Vous devez également publier les journaux LogCat pour savoir quelle exception vous obtenez et à quelle ligne. Si vous utilisez eclipse, ce sera en bas. Il suffit de copier et coller ici. – noob

Répondre

2

Utilisez adb logcat, DDMS, ou la perspective DDMS Eclipse pour examiner LogCat et regardez la trace de la pile associée à votre erreur.

En outre, jamais HARDWIRE chemins, d'autant plus /sdcard est faux - utiliser Environment.getExternalStorageDirectory() pour obtenir la racine de stockage externe.

Enfin, votre problème réel vient probablement de:

String outputPath= "/test_vga_output.jpg"; 

qui est un chemin non valide. Je ne sais pas où vous pensez que vous écrivez, mais vous ne pouvez pas écrire là. Cependant, vous pouvez avoir d'autres problèmes au-delà, et la trace de la pile vous aidera à les identifier.

Questions connexes