英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论