我可以使用 Glide 获取 refined/desired 位图来绘制 canvas 吗?

Can I use Glide to get refined/desired bitmap to draw on canvas?

如何使用 Glide Library 获取位图,因为我想在 canvas 上绘制该位图图像。 Glide 只允许我向 ImageView 添加图像。

有什么方法可以让我通过 Glide 获得精炼的位图,以便我可以将其绘制到 canvas。

目前我正在使用

Bitmap bitmapImage = BitmapFactory.decodeResource(getResources(), wallpaper_image_id);

我收到这个错误

java.lang.OutOfMemoryError: Failed to allocate a 43776012 byte allocation with 16767008 free bytes and 40MB until OOM

也许目标就是您所需要的。看看Here.

Glide.with(yourApplicationContext))
    .load(youUrl)
    .asBitmap()
    .into(new SimpleTarget<Bitmap>(myWidth, myHeight) {
        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
            // Do something with bitmap here.
        }
    };

onResourceReady 中,您已准备好要加载的位图。

编辑

您的应用程序崩溃是因为您需要 运行 在 ui 线程中编写代码。试试这个:

// Get a handler that can be used to post to the main thread
Handler mainHandler = new Handler(context.getMainLooper());

Runnable myRunnable = new Runnable() {
    @Override 
    public void run() {....} // Your code goes inside the run method
};
mainHandler.post(myRunnable);