本文主要是介绍subsampling-scale-image-view加载长图源码分析(二),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
subsampling-scale-image-view源码分析
- 概要
- 分析
- 总结
概要
subsampling-scale-image-view是一个支持部分加载大图长图的图片库,并且还支持缩放,在subsampling-scale-image-view加载长图源码分析(一)已经介绍过它的用法和部分源码,没有看过的朋友可以先移步看前面的分析。
分析
上回说到采样率等于1的情况下,因为不需要缩放和部分加载,所以直接调用了BitmapFactory进行解码,那么接下来我就来分析采样率大于1的情况。上代码:
private synchronized void initialiseBaseLayer(@NonNull Point maxTileDimensions) {debug("initialiseBaseLayer maxTileDimensions=%dx%d", maxTileDimensions.x, maxTileDimensions.y);satTemp = new ScaleAndTranslate(0f, new PointF(0, 0));fitToBounds(true, satTemp);// Load double resolution - next level will be split into four tiles and at the center all four are required,// so don't bother with tiling until the next level 16 tiles are needed.fullImageSampleSize = calculateInSampleSize(satTemp.scale);if (fullImageSampleSize > 1) {fullImageSampleSize /= 2;}if (fullImageSampleSize == 1 && sRegion == null && sWidth() < maxTileDimensions.x && sHeight() < maxTileDimensions.y) {// Whole image is required at native resolution, and is smaller than the canvas max bitmap size.// Use BitmapDecoder for better image support.decoder.recycle();decoder = null;BitmapLoadTask task = new BitmapLoadTask(this, getContext(), bitmapDecoderFactory, uri, false);execute(task);} else {initialiseTileMap(maxTileDimensions);List<Tile> baseGrid = tileMap.get(fullImageSampleSize);for (Tile baseTile : baseGrid) {TileLoadTask task = new TileLoadTask(this, decoder, baseTile);execute(task);}refreshRequiredTiles(true);}}
else里面就是采样率大于1的情况,
这篇关于subsampling-scale-image-view加载长图源码分析(二)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!