2016-03-28 8 views
1

このコードを使用して、画像ビュー(風景モード)でSdcardから画像を表示しています。しかし、イメージはその品質を失い、ぼやけてしまいます。ImageView AndroidでSdcardから表示すると画像がぼやける

 File imgFile = new File(imageFile.getAbsolutePath()); // path of your file 

       FileInputStream fis = null; 
       try { 
        fis = new FileInputStream(imgFile); 
       } catch (FileNotFoundException e) 
       { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
       BitmapFactory.Options options = new BitmapFactory.Options(); 
       options.inSampleSize = 8; 
       options.inPurgeable = true; 
       options.inScaled = true; 
       Bitmap bm = BitmapFactory.decodeStream(fis, null,options); 
       profileIV.setImageBitmap(bm); 

ImageViewのxmlファイル:

<ImageView 
    android:id="@+id/image11" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    > 
+1

コーディングハッピーオリエンテーション部分をスキップすることができ、これを試してみてくださいピカソについて知っているのであれば、ビットマップを作成する必要はありませんPicassoを使用して画像を表示するには、Picasso.with(mContext).load(Uri.fromFile(new File(imagePath))))。 –

+0

私はこれを試してみましょう –

+0

@mohit希望ピカソは作成されませんより大きいイメージのためのHeapsizeの問題 –

答えて

0

でも、私は同じ問題を抱えていたので、あなたは

 Bitmap bitmap; 
    try { 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inScaled = false; 
     options.inDither = false; 
     options.inPreferredConfig = Bitmap.Config.ARGB_8888; 

     // down sizing image as it throws OutOfMemory Exception for larger 
     // images 
     //options.inSampleSize = 16; 

     bitmap = BitmapFactory.decodeFile(filePath, options); 
     int orientation = getExifOrientation(filePath); 


     //rotate bitmap 
     Matrix matrix = new Matrix(); 
     matrix.postRotate(orientation); 
     //create new rotated bitmap 
     bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 
     ivProfile.setImageBitmap(bitmap); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

public static int getExifOrientation(String filepath) { 
    int degree = 0; 
    ExifInterface exif = null; 
    try { 
     exif = new ExifInterface(filepath); 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
    } 
    if (exif != null) { 
     int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); 
     if (orientation != -1) { 
      // We only recognise a subset of orientation tag values. 
      switch (orientation) { 
       case ExifInterface.ORIENTATION_ROTATE_90: 
        degree = 90; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_180: 
        degree = 180; 
        break; 
       case ExifInterface.ORIENTATION_ROTATE_270: 
        degree = 270; 
        break; 
      } 

     } 
    } 

    return degree; 
} 

関連する問題