模糊的位图在画布上

huangapple go评论59阅读模式
英文:

Blurred bitmap on canvas

问题

我在主活动中有一个基于视图的元素以及在可绘制文件夹中的[图像][1]

    public class MyView extends View {
        private Bitmap mSprite;
    
        public MyView(Context context, @Nullable AttributeSet attrs) {
            super(context, attrs);
            mSprite = BitmapFactory.decodeResource(getResources(), R.drawable.plank);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawBitmap(mSprite, 0.f, 0.f, null);
        }
    }

图像已显示但看起来模糊且过大[参考链接][2])。如何获取位图的实际大小并在画布上绘制它

  [1]: https://i.stack.imgur.com/eTAQS.png
  [2]: https://i.stack.imgur.com/kCbDX.jpg
英文:

I have View-based element in main activity and an image in drawable folder

public class MyView extends View {
    private Bitmap mSprite;

    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mSprite = BitmapFactory.decodeResource(getResources(), R.drawable.plank);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(mSprite, 0.f, 0.f, null);
    }
}

The image is displayed but looks blurry and too large (ref). How can I get the actual size of bitmap and draw in on canvas?

答案1

得分: 0

对于任何遇到上述问题的人:只需将您的图片放在“nodpi”文件夹中,它将与其实际大小匹配。

英文:

For anyone faced the above issue: just put your image in nodpi folder and it will match its actual size.

huangapple
  • 本文由 发表于 2020年9月8日 23:28:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63797062.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定