canvas.drawBitmap没有画任何东西 [英] canvas.drawBitmap is not drawing anything

查看:350
本文介绍了canvas.drawBitmap没有画任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 DragShadowBuilder 覆盖了 onDragShadow

@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?

推荐答案

如果您想按原样绘制位图(即,您想要整个东西),请使用:

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

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

第二个参数用于需要指定要绘制的位图子集的地方(可以如果不需要子集,则为null)。如果将src和dst(第二个和第三个参数)设置为同一对象,我希望该方法内有冲突。

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.

这篇关于canvas.drawBitmap没有画任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆