【问题标题】:Loading BitmapDrawable in Fresco在 Fresco 中加载 BitmapDrawable
【发布时间】:2018-04-13 10:33:37
【问题描述】:

所以我基本上有一种方法可以将一个图像转换为某种形状,然后从我的位图中进行 Drawable。现在有方法加载位图可绘制(setImageDrawable),但已弃用。

所以代码是这样的:

public static Drawable getDrawableFromName(String name, Activity activity) {
        int resourceId = activity.getResources().getIdentifier(name, "drawable", activity.getPackageName());

        if(resourceId == 0) {
            return null;
        } else {
            Bitmap croppedIcon = cropImage(activity, resourceId);
            if(croppedIcon == null)
                return null;
            return new BitmapDrawable(activity.getResources(), croppedIcon);
        }
    }

cropImage 返回具有一些自定义形状的位图图像。

我现在应该如何将这个可绘制对象加载到 Fresco SimpleDraweeView。是否有可能将其作为 Uri 资源?

【问题讨论】:

    标签: android fresco


    【解决方案1】:
    Uri uri = new Uri.Builder()
        .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
        .path(String.valueOf(resId))
        .build();
    
    simpleDraweeView.setImageURI(uri);
    

    【讨论】:

    • 但是我没有 resId,因为我生成了这个位图并且它没有保存在任何地方
    • 你可以将它临时存储在存储中吗?并且您正在将图像转换成这样的形状? :github.com/siyamed/android-shape-imageview
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多