这就是我想要的:在IndoorAtlas中加载平面图并显示当前位置。 这是我的代码:
public void loadFloorPlanImage(FloorPlan floorPlan) {
BitmapFactory.Options options = createBitmapOptions(floorPlan);
FutureResult<Bitmap> result = mIndoorAtlas.fetchFloorPlanImage(floorPlan,options);
result.setCallback(new ResultCallback<Bitmap>() {
@Override
public void onResult(final Bitmap result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setImageBitmap(result);
}
});
}
});
}
而且:
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;
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
options.inSampleSize = inSampleSize;
return options;
}
我收到错误结果:
java.lang.NullPointerException: Attempt to write to field 'int android.graphics.BitmapFactory$Options.inSampleSize' on a null object reference
at skripsi.ubm.studenttracking.indoor.createBitmapOptions(indoor.java:370)
at skripsi.ubm.studenttracking.indoor.loadFloorPlanImage(indoor.java:322)
at skripsi.ubm.studenttracking.indoor$1.onResult(indoor.java:163)
at skripsi.ubm.studenttracking.indoor$1.onResult(indoor.java:159)
你能帮帮我吗?
答案 0 :(得分:0)
你需要像这样初始化:
BitmapFactory.Options options = new BitmapFactory.Options();
options = createBitmapOptions(floorPlan);