2017-02-13 25 views
0

我想设置为我在Android API 23 CircleImageView图像我从设备的存储器中的图像路径和存储这个字符串数据库路径:setImageDrawable没有设置图像上API23

<de.hdodenhof.circleimageview.CircleImageView 
    android:id="@+id/fragment_edit_picture" 
    android:layout_width="150dp" 
    android:layout_height="150dp" 
    android:layout_gravity="center" 
    android:layout_margin="5dp" 
    android:src="@mipmap/ic_launcher" 
    android:onClick="selectFromGallery" 
    app:civ_border_width="2dp" 
/> 

它正在处理API 19和之前的版本,但它不适用于Genymotion中的Android版本API 23中的虚拟设备。所选图像未在ImageView中显示。我将图像设置为ImageView:

mCurrentImagePath = FileUtils.getPath(getActivity(), selectedImageUri); 
Log.d(TAG, "mCurrentImagePath: " + mCurrentImagePath); 

// Update client's picture 
if (mCurrentImagePath != null && !mCurrentImagePath.isEmpty()) { 
    fragmentEditPicture.setImageDrawable(new BitmapDrawable(getResources(), 
      FileUtils.getResizedBitmap(mCurrentImagePath, 512, 512))); 
} 

图像路径是mCurrentImagePath: /storage/emulated/0/Download/56836_(5-27-2006 2-28-40)(1920x1200).JPG

你知道为什么这不起作用吗?

+1

您是否在运行时请求了所需的权限? –

+0

@OgnianGloushkov号它没有得到任何错误或异常。它只是不设置图像。 –

回答

1

您正在使用的方法存在问题FileUtils.getResizedBitmap()。我创建了一个示例项目来重现您的问题。该示例项目中工作正常。使用下面的代码片段时,从设备的内存中加载图像时应该没有问题。

public static Bitmap getResizedBitmap(String imagePath, int width, int height) { 
    Bitmap bitmap = BitmapFactory.decodeFile(imagePath); 
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); 
    // Recycling the bitmap, because it's already used and not needed anymore 
    bitmap.recycle(); 
    return resizedBitmap; 
} 
+0

使用后回收原始的“位图”。首先使用'BitmapFactory.Options.inJustDecodeBounds'。 –

+0

@EugenPechanec哥们,对不起,我没有得到你说的确切内容!我是新的android.this是[FileUtils.getResizedBitmap()](http://codepad.org/c33ilHxK)。并在方法中使用options.inJustDecodeBounds = false;根据我的理解你的建议,我用这种方式[链接](http://codepad.org/oiskWKwf),但我得到错误[链接](http://codepad.org/wqGYmUHx) .sorry,非常感谢你 –

+0

'mCurrentImagePath'是我选择的图像路径不是uri。 –

相关问题