以下是我想要的內容:在IndoorAtlas中加載平面佈局並顯示當前位置。 這裏是我的代碼:使用IndoorAtlas將位圖顯示到UI線程中
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)
你能幫助我嗎?
你忘了初始化內部createBitmapOptions方法選項。 – Manish