【问题标题】:Draw on Bitmap in dependency to screen size根据屏幕大小在位图上绘制
【发布时间】:2012-07-04 10:05:31
【问题描述】:

我正在与另外两个人一起研究一个 Android 项目 (2.2)。

我们希望显示一些大学建筑的地图,以便您更轻松地找到房间。我们使用自定义的 ImageView (TouchImageView)。

我用

使位图可变

plant = plant.copy(Bitmap.Config.ARGB_8888, true);

这样我就可以将 Canvas 放在它上面。 然后我在它上面画了一个红色的圆圈

Paint paint = new Paint(); paint.setColor(Color.RED); Canvas canvas = new Canvas(plant); canvas.drawCircle(xFromSearch, yFromSearch, 15, paint);

xFromSearch 和 yFromSearch 是已经用给定值初始化的全局变量。

它在我的 Google G1 上运行良好,但在其他显示器尺寸(例如 AVD 或三星 Galaxy SII)上,圆圈绘制在错误的位置...

当我用它做某事时它会起作用

Display display = getWindowManager().getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();

??

我希望我已经为您提供了您需要的所有信息,并且有人可以提供帮助... 非常感谢!!!

【问题讨论】:

    标签: android canvas bitmap draw mutable


    【解决方案1】:

    试试这个

    int scale = getApplicationContext().getResources().getDisplayMetrics().density;
    canvas.drawCircle(xFromSearch*scale , yFromSearch*scale , 15*scale , paint);
    

    【讨论】:

    • 非常感谢!它有帮助^^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-01
    • 2014-05-18
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    相关资源
    最近更新 更多