1

I have overwritten onDragShadow for a DragShadowBuilder like so

@Override
    public void onDrawShadow(Canvas canvas) {
        super.onDrawShadow(canvas);
        Bitmap bitmap = InGameActivity.getRandomBitmap();
        Rect source = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        canvas.drawBitmap(bitmap, source, source, null);

    }

I have verified that the bitmap is not null but when I drag, nothing is showing. Any ideas why?

Kara
  • 6,115
  • 16
  • 50
  • 57
Ogen
  • 6,499
  • 7
  • 58
  • 124
  • Have you checked that the bitmap is not blank? Try logging some getPixel() calls. – Adam Bliss Jan 13 '14 at 02:28
  • 1
    Try canvas.drawBitmap(bitmap, null, source, null); There may be a conflict due to having src and dst set to the same object. If you don't need a subset of the bitmap drawn (i.e. you want the whole thing) then src should be null. – NigelK Jan 13 '14 at 08:39
  • @NigelK Ah yes, that worked. Please post ur comment as an answer so I can upvote and accept – Ogen Jan 13 '14 at 08:45
  • @Clay - Glad it worked (it was only an educated guess hence I didn't post it as an answer to begin with). – NigelK Jan 13 '14 at 09:42

2 Answers2

3

If you want to draw the bitmap as is (i.e. you want the whole thing), use:

canvas.drawBitmap(bitmap, null, source, null);

The 2nd parameter is for where you need to specify a subset of the bitmap to be drawn (it can be null if no subset is required). I expect there is a conflict within the method if you have src and dst (2nd and 3rd parameters) set to the same object.

NigelK
  • 8,255
  • 2
  • 30
  • 28
  • 1
    This code is confusing because 'source' is meant to be in 2nd place, not 3rd. Perhaps the rect should be renamed to 'dst'? That way it wouldn't look like you've confused 'src' and 'dst'. – Tim Cooper Apr 19 '18 at 05:41
2

Checklist:

  1. Is the bitmap valid, i.e. not all transparent or the same as the background colour? You can view it easily in the Android studio debugger.

  2. Is your source rectangle (i.e. parameter 2, not 3 as is confusingly shown above) within the bounds of the bitmap? You're allowed to set this to null and that can be a good debugging step.

  3. Is your destination rectangle within the bounds of the canvas?

  4. Do you have a 4th parameter, 'paint', which has a low alpha value? Try 'paint.setAlpha(255)' or use 'null' for the 4th parameter.

  5. Do you see this message in your console? "OpenGLRenderer: Bitmap too large to be uploaded into a texture"? If so then see: "Bitmap too large to be uploaded into a texture"

Tim Cooper
  • 10,023
  • 5
  • 61
  • 77
  • Awesome answer, thank you. And one more thing. In my case the problem was in "wrong" canvas. I mean it was canvas on another view. Rare mistake, but it also possible. – Yazon2006 Apr 22 '19 at 08:50