【问题标题】:Pixels, Density, Screen Resolution - of a Bitmap on Surface View?像素,密度,屏幕分辨率 - Surface View 上的位图?
【发布时间】:2015-02-18 18:23:26
【问题描述】:

我想知道是否有人可以帮助我正确理解与我的程序相关的这些原则。 我有一个表面视图,我正在其画布上绘制位图。 我发现这段代码可以计算出不同分辨率和屏幕密度下的位图大小。

WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
   Display display = wm.getDefaultDisplay();

    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
        Point size = new Point();
        display.getSize(size);
        Log.e("XXX", "Display w/h: " +size.x + "/" + size.y);

    bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.speedo); 
    int width = bmp1.getWidth();
    int height = bmp1.getHeight();
    Log.e("XXX", "w/h: " + width + "/" + height);

    float scaleWidth = metrics.scaledDensity;
    float scaleHeight = metrics.scaledDensity;
    Log.e("XXX", "w/h: " + scaleWidth + "/" + scaleHeight);

    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);

    // recreate the new Bitmap
    bmp2 = Bitmap.createBitmap(bmp1, 0, 0, width, height, matrix, true);

在画布上绘制后,我在 3 台设备上记录了我的值。

  1. GenyMotion 模拟器 (598x360) [scale1.0]
  2. LG Optimus2x (800x480) [scale1.5]
  3. OnePlus1(1980x1080) [scale3.0]

我(在 Adob​​e 中)制作的图像(位图)为 800 x 179 像素 @ 72 像素/英寸

在 GENYMOTION= 中显示为 267 x 60

在 Lg = 它出现在 400 x 90

在 OnePlus1= 中显示为 800 x 179

我知道尺寸如何根据比例变化,但在 1plus1 中虽然它说长度为 800,但它比屏幕长,即 1980!?这个怎么可能? 有人能解释一下到底发生了什么的逻辑吗?

【问题讨论】:

    标签: android canvas bitmap


    【解决方案1】:

    是的,我找到了原因:- 这是因为我的 RnD 错误。

    在创建 bmp2 然后绘制之后,我没有测量它。所以它实际上是 800x3=2400,即 > 1980(屏幕长度)!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 2014-12-25
      • 2011-07-04
      • 2011-01-01
      • 2015-06-12
      相关资源
      最近更新 更多