2017-10-19 12 views
0

私はExifInterfaceをAndroidアプリで使用しました。私のコードはで完璧に動作します。しかし、ビルドバージョンが24以上の場合は、アンドロイドスタジオのlogcatで警告が表示され、正しく動作しません。ここでExifInterfaceにサポートされていない画像があります

はonActivityResultメソッドから私のコードブロックです:私はカメラから画像を選ぶ際

if(requestCode == REQUEST_CAPTURE_IMG && resultCode == RESULT_OK) { 
      Log.d(TAG, "Inside camera operation"); 
      int reqWidth = 480, reqHeight = 800; 
      try { 
       InputStream inStream = null; 
       try { 
        inStream = getContentResolver().openInputStream(imageUri); 

        //Decode image size 
        BitmapFactory.Options options = new BitmapFactory.Options(); 
        options.inJustDecodeBounds = true; 

        BitmapFactory.decodeStream(inStream, null, options); 
        inStream.close(); 

        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); 

        options.inJustDecodeBounds = false; 
        inStream = getContentResolver().openInputStream(imageUri); 

        CommonStaticClass.mImage = BitmapFactory.decodeStream(inStream, null, options); 

        ExifInterface exif = null; 

        try { 
         //File pictureFile = new File(imgDecodableString); 
         if (Build.VERSION.SDK_INT >= 24) { 
          exif = new ExifInterface(inStream); 
          Log.d("exif", "sdk 24"); 
         } 
         else { 
          exif = new ExifInterface(imageUri.getPath()); 
         } 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 

        int orientation = ExifInterface.ORIENTATION_NORMAL; 

        if (exif != null) 
         orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); 

        switch (orientation) { 
         case ExifInterface.ORIENTATION_ROTATE_90: 
          CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 90); 
          break; 
         case ExifInterface.ORIENTATION_ROTATE_180: 
          CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 180); 
          break; 

         case ExifInterface.ORIENTATION_ROTATE_270: 
          CommonStaticClass.mImage = rotateBitmap(CommonStaticClass.mImage, 270); 
          break; 
        } 

        inStream.close(); 
       } catch (IOException e) { 
        //Toast.makeText(this, "IO exception", Toast.LENGTH_SHORT).show(); 
        Toast.makeText(this, SelectSuitActivity.this.getString(R.string.wrong_msg), Toast.LENGTH_SHORT).show(); 
       } 
       //CommonStaticClass.mImage = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri); 
       startActivity(intent); 
      } catch (Exception e) { 
       Toast.makeText(this, SelectSuitActivity.this.getString(R.string.wrong_msg), Toast.LENGTH_SHORT).show(); 
      } 
     } 

そしてここでは、logcatの結果である:

10-19 12:39:04.399 2912-2912/com.example.myapp I/ExifInterface_JNI: Corrupted image. 
    10-19 12:39:04.414 2912-2912/com.example.myapp W/ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface. 
    java.io.EOFException 
    at java.io.DataInputStream.readByte(DataInputStream.java:270) 
    at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1834) 
    at android.media.ExifInterface.loadAttributes(ExifInterface.java:1475) 
    at android.media.ExifInterface.<init>(ExifInterface.java:1174) 
    at com.lostsym.founder.SelectSuitActivity.onActivityResult(SelectSuitActivity.java:621) 
    at android.app.Activity.dispatchActivityResult(Activity.java:6932) 
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4085) 
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4132) 
    at android.app.ActivityThread.-wrap20(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1533) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

誰が何を見つけ出すことができればそれが役立つだろうここで間違っている。ありがとうございました。

+0

jpgファイルが壊れています。または、サポートされていないイメージ形式を使用します。 – greenapps

+2

InStreamは、BitmapFactoryで使用された後で使用します。それは不可能です。もう一度ストリームを開きます。 – greenapps

+0

@greenappsありがとうございます。あなたの提案は私の問題を解決します。 –

答えて

1

InStreamは、BitmapFactoryで使用された後で使用します。それは不可能です。もう一度ストリームを開きます。

関連する問題