2012-04-16 68 views
0

我是新來的android。我正在嘗試做某種圖像處理。但是我收到這個消息「這個應用程序---意外停止了,請重試。」請告訴我什麼錯誤,我正在安卓應用做力關閉

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

嗨,你需要發佈LogCat日誌,以知道你得到哪個異常,以及在哪一行。如果你使用的是eclipse,它會在底部。只需在這裏複製並粘貼。 – noob 2012-04-16 14:43:09

回答

2

使用adb logcat,DDMS,或在Eclipse中DDMS角度來考察logcat的,看看你的錯誤相關的堆棧跟蹤。

此外,從來沒有硬線路徑,特別是因爲/sdcard是錯誤的 - 使用Environment.getExternalStorageDirectory()獲得外部存儲的根。

最後,您的實際問題可能來自:

String outputPath= "/test_vga_output.jpg"; 

這是一個無效的路徑。我不知道你在想什麼,但是你不能在那裏寫。但是,除此之外,您可能還有其他問題,堆棧跟蹤將幫助您識別它們。