【问题标题】:Create Bitmap Options Using IndoorAtlas使用 IndoorAtlas 创建位图选项
【发布时间】:2015-04-30 03:03:48
【问题描述】:

我有以下代码:

void loadFloorPlanImage(FloorPlan floorPlan) {
BitmapFactory.Options options = createBitmapOptions(floorPlan);
FutureResult<Bitmap> result = ia.fetchFloorPlanImage(floorPlan, options);
result.setCallback(new ResultCallback<Bitmap>() {
        @Override
        public void onResult(final Bitmap result) {
           // now you have floor plan bitmap, do something with it
           updateImageViewInUiThread(result);
        }
        // handle error conditions
}
}

我感到困惑的是:

BitmapFactory.Options 选项 = createBitmapOptions(floorPlan);

我应该在“createBitmapOptions”中做什么?

【问题讨论】:

    标签: android indoor-positioning-system


    【解决方案1】:

    这不是 IndoorAtlas 特定的问题。您可以调整例如要生成的位图图像的大小,或者简单地将选项保留为空。看http://developer.android.com/reference/android/graphics/BitmapFactory.html

    如果您想限制要在应用的地图视图中使用的图像的最大尺寸,示例可能如下所示:

    private BitmapFactory.Options createBitmapOptions(FloorPlan floorPlan) {
    
        int reqWidth = 2048;
        int reqHeight = 2048;
    
        final int width = (int) floorPlan.dimensions[0];
        final int height = (int) floorPlan.dimensions[1];
        int inSampleSize = 1;
    
        if (height > reqHeight || width > reqWidth) {
    
            final int halfHeight = height / 2;
            final int halfWidth = width / 2;
    
            // Calculate the largest inSampleSize value that is a power of 2 and keeps both
            // height and width larger than the requested height and width.
            while ((halfHeight / inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize) > reqWidth) {
                inSampleSize *= 2;
            }
    
        }
    
        options.inSampleSize = inSampleSize;
        return options;
    
    }
    

    【讨论】:

    • 我已经关注了您的代码并得到了这个结果:进程:skripsi.ubm.studenttracking,PID:19086 java.lang.NullPointerException:尝试写入字段'int android.graphics.BitmapFactory$Options。 inSampleSize' 在 skripsi.ubm.studenttracking.indoor.createBitmapOptions(indoor.java:370) 在 skripsi.ubm.studenttracking.indoor.loadFloorPlanImage(indoor.java:322) 在 skripsi.ubm.studenttracking.indoor$1 的空对象引用.onResult(indoor.java:163) at skripsi.ubm.studenttracking.indoor$1.onResult(indoor.java:159)
    猜你喜欢
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    相关资源
    最近更新 更多