2016-03-28 57 views
1

我使用此代码在图像视图(风景模式)中显示来自Sdcard的图像。但图像质量下降,模糊。从ImageView中的Sdcard中显示时,图像变得模糊Android

 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

如果您知道毕加索比您不需要创建位图简单地使用您的图像(mContext).load(Uri.fromFile(new File(imagePath)))。)转换为(imgView);然后使用Picasso来显示你的图像。 –

+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; 
} 

编码快乐