We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
开发过程中发现图片太大会导致内存溢出,使用BasePostprocessor重写方法降低图片的宽高比,结果出现Pool hard cap violation的问题
val request: ImageRequest = ImageRequestBuilder.newBuilderWithSource(uri) .setPostprocessor(object : BasePostprocessor(){ override fun process(destBitmap: Bitmap?, sourceBitmap: Bitmap?) { destBitmap ?: return sourceBitmap ?: return internalCopyBitmap(destBitmap, sourceBitmap) process(destBitmap) } override fun process( sourceBitmap: Bitmap?, bitmapFactory: PlatformBitmapFactory? ): CloseableReference<Bitmap> { if(sourceBitmap == null || bitmapFactory == null){ return super.process(sourceBitmap, bitmapFactory) } val sourceBitmapConfig = sourceBitmap.config ?: FALLBACK_BITMAP_CONFIGURATION val allocationByteCount = sourceBitmap.allocationByteCount // to do: optimize maxAllocationByteCount's value val maxAllocationByteCount = 50 * 1024 *1024 val scale = if(allocationByteCount > maxAllocationByteCount){ maxAllocationByteCount.toFloat() / allocationByteCount.toFloat() }else{ 1f } val destBitmapRef = bitmapFactory.createBitmapInternal( (sourceBitmap.width * scale).toInt(), (sourceBitmap.height * scale).toInt(), sourceBitmapConfig ) return try { process(destBitmapRef.get(), sourceBitmap) CloseableReference.cloneOrNull(destBitmapRef)!! } finally { CloseableReference.closeSafely(destBitmapRef) } } } ) .build()
看源码发现ArtBitmapFactory.createBitmapInternal -> mBitmapPool.get(sizeInBytes) -> canAllocate最后返回了false
ArtBitmapFactory.createBitmapInternal -> mBitmapPool.get(sizeInBytes) -> canAllocate
我想通过获取canAllocate的最大值,赋值给maxAllocationByteCount从而得到 满足内存 且 失真最低 的缩放比
The text was updated successfully, but these errors were encountered:
No branches or pull requests
背景
开发过程中发现图片太大会导致内存溢出,使用BasePostprocessor重写方法降低图片的宽高比,结果出现Pool hard cap violation的问题
详细描述
看源码发现
ArtBitmapFactory.createBitmapInternal -> mBitmapPool.get(sizeInBytes) -> canAllocate
最后返回了false问题
我想通过获取canAllocate的最大值,赋值给maxAllocationByteCount从而得到 满足内存 且 失真最低 的缩放比
The text was updated successfully, but these errors were encountered: