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


Krunal Agnihotri

How can I get a bitmap using Glide Library as I want to draw that bitmap image on canvas. Glide only allows me to add an image to the ImageView.

Is there any way to get a refined bitmap with Glide so that it can be drawn to the canvas.

Currently I am using

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

i get this error

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

Maybe goals are all you need. Check it out 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.
        }
    };

In it, onResourceReadyyou are ready to load the bitmap to the desired location.

edit

Your app is crashing because you need to run your code in the UI thread. Try this:

// 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);

Related


Draw bitmap to canvas with alpha gradient

Cactus I want to draw one Bitmapon Canvas, with a (linear) alpha-gradient applied. The important point is that I don't want to overwrite the image with any other colors. The background (from the back I've drawn it to ) should just "shine". To illustrate this,

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

Draw bitmap as line on canvas

Vasily Kuragov Right now, I'm writing my small drawing application, and one of its features is custom brushes from bitmaps. I thought it wouldn't be a big problem that onTouchEvent() calls every action and draws the bitmap on every pixel, but when I swipe quic

How to draw on canvas and convert to bitmap?

Matt Matt I want to draw some lines and shapes on canvas and then convert it to bitmap on ImageView. I am extending "View" in a custom class, and on the "OnDraw method" I am drawing lines. Here is my code (this class only draws simple lines): public class fina

Draw bitmap to canvas with alpha gradient

Cactus I want to draw one Bitmapon Canvas, with a (linear) alpha-gradient applied. The important point is that I don't want to overwrite the image with any other colors. The background (from the back I've drawn it to ) should just "shine". To illustrate this,

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

How to draw on canvas and convert to bitmap?

Matt Matt I want to draw some lines and shapes on canvas and then convert it to bitmap on ImageView. I am extending "View" in a custom class, and on the "OnDraw method" I am drawing lines. Here is my code (this class only draws simple lines): public class fina

Draw bitmap as line on canvas

Vasily Kuragov Right now, I'm writing my small drawing application, and one of its features is custom brushes from bitmaps. I thought it wouldn't be a big problem that onTouchEvent() calls every action and draws the bitmap on every pixel, but when I swipe quic

Draw a bitmap along a path on the canvas

Salman Khakwani I'm trying to create a drawing application that will be able to draw different brush textures along a touch path on the screen. What I've done so far: Here's the code for my "custom view": public class TestDrawingView extends View{ private Bit

Draw bitmap on canvas with custom shape

username I want to draw an image of the following shape on a canvas: Black has to be replaced with my image. I currently draw the image as a whole. I just don't know how to get this shape? canvas.drawBitmap(header,0,0,mPaint); Can someone help me? usernam

Draw a bitmap along a path on the canvas

Salman Khakwani I'm trying to create a drawing application that will be able to draw different brush textures along a touch path on the screen. What I've done so far: Here's the code for my "custom view": public class TestDrawingView extends View{ private Bit

Struggling to make a canvas with a bitmap and draw on it

username Here is my code so far. Edit: Added full code. public void enterPreviewMode(byte[] pictureData) { //Stop preview and enter review mode previewPic = true; cam.stopPreview(); //Find buttons and make them visible/invisible Button ta

How to draw 3 bitmap on canvas

Christopher M. I'm trying to combine 3 imageViews into one bitmap, and I'm using canvas, here is the function private Bitmap createSingleImageFromMultipleImages() { Bitmap formBitmap = getBitmapFromImageView(formView); Bitmap idFrontBitmap = getBitmap

Draw bitmap as line on canvas

Vasily Kuragov Right now, I'm writing my small drawing application, and one of its features is custom brushes from bitmaps. I thought it wouldn't be a big problem that onTouchEvent() calls every action and draws the bitmap on every pixel, but when I swipe quic

Draw bitmap to canvas with alpha gradient

cactus I want to draw one Bitmapon Canvas, with a (linear) alpha-gradient applied. The important point is that I don't want to overwrite the image with any other colors. The background (from the back I've drawn it to ) should just "shine". To illustrate this,

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

On Firemonkey, how do I draw a masked bitmap on a canvas?

username I have a bitmap and a mask (also a bitmap). I want to draw a bitmap on the mask (as shown in the image below) How can I do this on Delphi using Firemonkey ? Tom Bromberg useTBitmap.CreateFromBitmapAndMask() constructor CreateFromBitmapAndMask(const Bi

Draw bitmap as line on canvas

Vasily Kuragov Right now, I'm writing my small drawing application, and one of its features is custom brushes from bitmaps. I thought it wouldn't be a big problem that onTouchEvent() calls every action and draws the bitmap on every pixel, but when I swipe quic

Draw bitmap as line on canvas

Vasily Kuragov Right now, I'm writing my small drawing application, and one of its features is custom brushes from bitmaps. I thought it wouldn't be a big problem that onTouchEvent() calls every action and draws the bitmap on every pixel, but when I swipe quic