How to calculate the average color of a UIImage?

前端 未结 6 1810
花落未央
花落未央 2021-02-01 07:55

I want to build an app that lets the user select an image and it outputs the \"average color\".

For example, this image:

The average color would be a gr

6条回答
  •  耶瑟儿~
    2021-02-01 08:24

    If you want an exact result, I believe that whatever you do, either yourself or through an API, you will go through all the pixels at least once anyways.

    You currently use already assigned (existing) memory so that means that at least you wont crash :)

    If freezing is the issue, it is because you are executing in the UI thread and should move all this processing in a background thread such as by using an AsyncTask.

    You could try to resize the imageview, get the rendering buffer and work on that image but you will use more memory and I dont believe it will be faster either.

提交回复
热议问题