2013-01-12 7 views
0

두 개의 컬러 사진을 회색조로 변환하고 픽셀별로 비교하는 데 사용하는 코드입니다. 내 애플 리케이션 강제 폐쇄를 유지합니다. 코드는 다음과 같습니다.ColorBitmap을 GrayscaleBitmap으로 변환하면 충돌이 계속됩니다.

public boolean equals(Bitmap bitmap1, Bitmap bitmap2) { 
     Bitmap grayscaleBitmap1 = Bitmap.createBitmap(
       bitmap1.getWidth(), bitmap1.getHeight(), 
       Bitmap.Config.RGB_565); 

      Canvas c = new Canvas(grayscaleBitmap1); 
      Paint p = new Paint(); 
      ColorMatrix cm = new ColorMatrix(); 

      cm.setSaturation(0); 
      ColorMatrixColorFilter filter = new ColorMatrixColorFilter(cm); 
      p.setColorFilter(filter); 
      c.drawBitmap(bitmap1, 0, 0, p); 
      Bitmap grayscaleBitmap2 = Bitmap.createBitmap(
        bitmap2.getWidth(), bitmap2.getHeight(), 
        Bitmap.Config.RGB_565); 
      Canvas c1 = new Canvas(grayscaleBitmap2); 
      c1.drawBitmap(bitmap2, 0, 0, p);  
     ByteBuffer buffer1 = ByteBuffer.allocate(grayscaleBitmap1.getHeight() 
       * grayscaleBitmap1.getRowBytes()); 
     grayscaleBitmap1.copyPixelsToBuffer(buffer1); 

     ByteBuffer buffer2 = ByteBuffer.allocate(grayscaleBitmap2.getHeight() 
       * grayscaleBitmap2.getRowBytes()); 
     grayscaleBitmap2.copyPixelsToBuffer(buffer2); 

     return Arrays.equals(buffer1.array(), buffer2.array()); 
    } 

여기는 logcat입니다.

답변

1
01-12 10:12:48.947: E/AndroidRuntime(2052): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
01-12 10:12:48.947: E/AndroidRuntime(2052):  at android.os.Handler.<init>(Handler.java:121) 
01-12 10:12:48.947: E/AndroidRuntime(2052):  at android.widget.Toast.<init>(Toast.java:68) 

이 줄들은 비동기 작업의 어딘가에 토스트를 작성했다고 말합니다. 토스트를 에 넣으십시오. runOnUiThread(); 아래에 나와 있습니다 :

runOnUiThread(new Runnable() {   
      @Override 
      public void run() { 
      Toast.makeText(yourActivity.this, "your Text Here!",1000).show();        
      } 
    }); 

그리고 완료되었습니다.

+0

내게 어색했다. 감사. –

+0

나는 어떻게 작성해야 this.please 체크 –

+0

내가 어떻게 해야할지, 그냥 AsyncTask에 몇 가지 코드를 붙여 그것을 토스트했다 실현하지 않았다. –

관련 문제