在位图中获取图像但仅返回黑色像素

时间:2016-04-15 05:13:01

标签: android imageview android-bitmap

我试图将图像位图设置为显示黑色像素,我也尝试了图像URI但又设置了黑色像素但是当我调试它时,位图和uri图像得到了正确的图像,但这两种方法都不能在imageview中设置它。

`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());
    }
`

见图像

the bitmap value and imageview value

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:1)

你可以使用毕加索:

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