Why does saving a bitmap take so long?

和自甴很熟 提交于 2019-11-29 07:34:42

I am not using the Google Glass, but faced this same problem. So I am going to document my findings here.

My bitmap was taking a long time to save. It took me nearly 4 sec to save a bitmap of size 1200x1200 and the final saved file size was 2MB. But I didn't need that level of clarity and file size. When I mean "save", it means the actual saving to the disk alone and not the time taken by the Android OS to detect it as a media item.


ACTUAL SAVE: Try out the following if you find the saving of bitmap to be slow:

  1. Try to use JPEG format and use PNG only when it is absolutely necessary. Use bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
  2. If you are creating the bitmap and you don't care about the transparency, then use Bitmap.Config.RGB_565 instead of Bitmap.Config.ARGB_8888.

    Use Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);


DETECTION IN FILE MANAGER:

Once you have saved the bitmap as a File in the Storage, the Android OS won't immediately show this file in the File Manager or in the explorer when you connect it to your PC. In order to do this detection fast, you need to use MediaScannerConnection.

MediaScannerConnection.scanFile(getActivity(), new String[]{file.toString()}, null, null);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!