difference between methods to scale a bitmap

﹥>﹥吖頭↗ 提交于 2019-12-05 03:23:44
emmby

Using BitmapFactory with the proper inScale options will allow you to be more memory efficient than using either Bitmap.createScaledBitmap() or Bitmap.createBitmap() with a matrix scale. However, it is more complicated.

Check out How do I scale a streaming bitmap in-place without reading the whole image first? for details.

There is no "big" difference. Although, one benefit with using the BitmapFactory.Options is that you can check for the width / height of your Bitmap without allocating memory for the actual Bitmap's pixels.

Also, you can easily see which options BitmapFactory.Options has and compare that with Bitmap.createBitmap(). In general, BitmapFactory.Options is like a "tool" API for making decoding and sampling Bitmaps easier.

One difference that I found was that using BitmapFactory`s options.inSampleSize to scale bitmaps is not as granular, because the scale will be 1/inSampleSize, and because inSampleSize must be an integral number, you wind up with scaling like 1/2, 1/3, 1/4, etc, but nothing more granular than that.

Bitmap.createScaledBitmap(), though more memory intensive, allows more granular scaling, up to 1dp resolution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!