2012-04-16 2 views
0

나는 안드로이드를 처음 접했다. 나는 이미지 처리를하려고 노력 중이다. 하지만이 메시지가 "이 응용 프로그램이 예기치 않게 중지되었습니다. 다시 시도하십시오."라는 메시지가 나타납니다. 내가 사용 adb logcatandroid application near 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

안녕하세요, 귀하는 어떤 예외를 받고 어떤 라인이 있는지 알기 위해 LogCat 로그도 게시해야합니다. 이클립스를 사용하고 있다면 하단 하단에 있습니다. 그냥 복사하여 여기에 붙여 넣으십시오. – noob

답변

2

을하고있는 무슨 실수 친절하게 말해, DDMS는, 또는 이클립스의 DDMS 관점 로그 캣을 검사하고 오류와 연결된 스택 추적 볼 수 있습니다. 또한

, 결코 /sdcard 잘못 특히 때문에, 경로를를 하드 와이어 없습니다 - 외부 저장 장치의 루트를 얻을 수 Environment.getExternalStorageDirectory()를 사용합니다. 잘못된 경로입니다

String outputPath= "/test_vga_output.jpg"; 

:

마지막으로, 실제 문제는 아마에서 온다. 나는 당신이 당신이 쓰고 있다고 생각하는 것을 모르지만 거기에 글을 쓸 수는 없습니다. 그러나 그 외의 추가 문제가있을 수 있으며 스택 추적은 사용자를 식별하는 데 도움이됩니다.