1

Here it says this

BitmapDrawable() This constructor was deprecated in API level 4. Use BitmapDrawable(android.content.res.Resources, android.graphics.Bitmap) instead to specify a bitmap to draw with and ensure the correct density is set.

I'm trying to set a temporary image Before an image is loaded. To get to this point I used this tutorial which gave me this function to get a color temporary instead of an image using this function :

static class DownloadedDrawable extends ColorDrawable {
    private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

    public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask) {
        super(Color.BLACK);
        bitmapDownloaderTaskReference =
            new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask);
    }

    public BitmapDownloaderTask getBitmapDownloaderTask() {
        return bitmapDownloaderTaskReference.get();
    }
}

I got to the idea to use the BitmapDrawable by this question If you know another way to do this I will of course be happy to use it but I prefer not to use a lib.

Community
  • 1
  • 1
Shishi
  • 601
  • 2
  • 8
  • 27

2 Answers2

0

try to use new BitmapDrawable(context.getResources(), canvasBitmap);

Lucian Novac
  • 1,255
  • 12
  • 18
  • I think I just don't really understand the method since this sets a color and I want it to be a image so that simple line can't help me as I don't know where to place it. – Shishi Feb 28 '14 at 08:59
0

If you want to show a bitmap instead of a solid colour, extend from BitmapDrawable:

static class DownloadedDrawable extends BitmapDrawable {
private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;

public DownloadedDrawable(Resources resources, Bitmap bitmap, BitmapDownloaderTask bitmapDownloaderTask) {
    super(resources, bitmap);
    bitmapDownloaderTaskReference =
        new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask);
}

public BitmapDownloaderTask getBitmapDownloaderTask() {
    return bitmapDownloaderTaskReference.get();
}
}

To use it:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.your_drawable);
DownloadedDrawable draw = new DownloadedDrawable(getResources(), bitmap, yourBitmapDownloaderTask);
yourImageView.setImageDrawable(draw);
FunkTheMonk
  • 10,908
  • 1
  • 31
  • 37