Android/Tip&Tech
Called reconfigure on a bitmap that is in use! This may cause graphical corruption!
행복한 수지아빠
2017. 2. 14. 12:03
반응형
public class TileBitmapProvider implements BitmapProvider {
private final TileProvider provider;
private final Bitmap.Config bitmapConfig;
private final int backgroundColor;
private final BitmapPool bitmapPool;
private final Rect frameRect = new Rect();
public TileBitmapProvider(final TileProvider provider,
final BitmapPool bitmapPool,
final Bitmap.Config bitmapConfig,
final int backgroundColor) {
this.provider = provider;
this.bitmapConfig = bitmapConfig;
this.backgroundColor = backgroundColor;
this.bitmapPool = bitmapPool;
}
@Override public Bitmap getBitmap(final Tile tile, final Context context) {
try {
Bitmap bmp = tile.getBitmap();
if (bmp == null || bmp.isRecycled()) {
bmp = bitmapPool.poll();
bmp = bmp != null ? bmp : Bitmap.createBitmap(tile.getWidth(), tile.getHeight(), bitmapConfig);
// tiles at edges need to be padded so that they fit correctly
bmp.eraseColor(backgroundColor);
final BitmapFactory.Options ops = new BitmapFactory.Options();
ops.inPreferredConfig = bitmapConfig;
ops.inBitmap = bmp;
ops.inMutable = true;
frameRect.set(0, 0, tile.getWidth(), tile.getHeight());
bmp = BitmapRegionDecoder.newInstance(provider.readTile(tile), false).decodeRegion(frameRect, ops);
}
return bmp;
} catch (final IOException e) {
Logger.getInstance().critical(getClass().getSimpleName(), e, "Error loading tile:");
}
return null;
}
}
다음은 경고를 트리거하는 코드입니다.
public class TileBitmapProvider implements BitmapProvider {
private final TileProvider provider;
private final Bitmap.Config bitmapConfig;
private final int backgroundColor;
private final BitmapPool bitmapPool;
public TileBitmapProvider(final TileProvider provider,
final BitmapPool bitmapPool,
final Bitmap.Config bitmapConfig,
final int backgroundColor) {
this.provider = provider;
this.bitmapConfig = bitmapConfig;
this.backgroundColor = backgroundColor;
this.bitmapPool = bitmapPool;
}
@Override public Bitmap getBitmap(final Tile tile, final Context context) {
try {
Bitmap bmp = tile.getBitmap();
if (bmp == null || bmp.isRecycled()) {
bmp = bitmapPool.poll();
bmp = bmp != null ? bmp : Bitmap.createBitmap(tile.getWidth(), tile.getHeight(), bitmapConfig);
// tiles at edges need to be padded so that they fit correctly
bmp.eraseColor(backgroundColor);
final BitmapFactory.Options ops = new BitmapFactory.Options();
ops.inPreferredConfig = bitmapConfig;
ops.inBitmap = bmp;
ops.inMutable = true;
bmp = BitmapFactory.decodeStream(provider.readTile(tile), null, ops);
}
return bmp;
} catch (final IOException e) {
Logger.getInstance().critical(getClass().getSimpleName(), e, "Error loading tile:");
}
return null;
}
}
반응형