«   2019/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Tags
more
Archives
Today
27
Total
1,681,324
관리 메뉴

올해는 머신러닝이다.

Called reconfigure on a bitmap that is in use! This may cause graphical corruption! 본문

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;
    }
}


0 Comments
댓글쓰기 폼