2016-03-28 4 views
1

Ich verwende diesen Code, um Bild von Sdcard in der Bildansicht (im Querformat) anzuzeigen. Aber das Bild verliert seine Qualität und es ist verschwommen.Bild wird unscharf, wenn die Anzeige von Sdcard in ImageView 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); 

Image XML-Datei:

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

überspringen Wenn Sie über Picasso wissen, müssen Sie nicht einfach Bitmap erstellen Pfad und zeigen Sie Ihr Bild mit Picasso, versuchen Sie diese Picasso.with (mContext) .load (Uri.fromFile (neue Datei (imagePath))). in (imgView); –

+0

Lassen Sie mich versuchen –

+0

@mohit hoffe Picasso wird nicht erstellen Heapsize-Problem für ein größeres Bild –

Antwort

0

dies versuchen, denn auch das gleiche Problem, das ich hatte, können Sie die Ausrichtung Teil

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

Glücklich Coding

Verwandte Themen