2016-04-15 5 views
0

Ich bin versucht, das Bild Bitmap zu setzen es schwarze Pixel zeigte und ich auch versucht Bild URI aber wieder schwarze Pixel setzen Aber wenn ich es debuggte, werden die Bitmap und URI Bild bekommen das richtige Bild, aber beide Methoden sind nicht in der Lage, es in der Bildansicht zu setzen.das Bild in Bitmap bekommen aber nur schwarze Pixel zurück

`ImageView imageView = (ImageView) rootView.findViewById(R.id.imagef); 
    try 
    { 
     String profileImagePath = Environment.getExternalStorageDirectory().toString() + "/MYFolder/"+ Configuration.empcode+".jpg"; 
     File profilepath = new File(profileImagePath); 
     if(profilepath.exists()) 
     { 

      //need to resolve 
      Bitmap bmp = BitmapFactory.decodeFile(profileImagePath); 

      Uri uri = Uri.fromFile(new File(profileImagePath)); 
//    imageView.setImageBitmap(bmp); 
      imageView.setImageURI(uri); 
     } 
    } 
    catch(Exception e) 
    { 
     Log.d("Profile Image Exception", e.toString()); 
    } 
` 

sehen, das Bild hier

the bitmap value and imageview value

+0

Was ist die Dateilänge dieser jpg-Datei? Und es ist Auflösung? Überprüfen Sie, ob 'bmp' null ist. – greenapps

Antwort

2
ImageView imageView = (ImageView) rootView.findViewById(R.id.imagef); 
String profileImagePath = Environment.getExternalStorageDirectory().toString() + "/MYFolder/"+ Configuration.empcode+".jpg"; 
File profilepath = new File(profileImagePath); 
Picasso.with(activity_or_fragment_context).load(profilePath).placeholder(R.drawable.any_place_holder_png_file).fit().centerCrop().into(imageView); 
+0

Habe es gerade funktioniert. kannst du mir bitte erklären, warum das passierte (Schwarze Pixel) Vielen Dank –

+1

Weil Picasso das Bild in der Größe verändert. Du hast das nicht gemacht. Dein Original ist so groß, dass BitmapFactoty.decodeFile null zurückgibt. – greenapps

+0

ok du hast es gerettet mann. Danke –

1

Sie Picasso verwenden:

String profileImagePath = Environment.getExternalStorageDirectory().toString() + "/MYFolder/"+ Configuration.empcode+".jpg"; 
    File profilepath = new File(profileImagePath); 
    Picasso.with(yourActivityContext).load(profilepath).into(imageView);