Skip to content

Commit

Permalink
Utilized getPixels for Bitmap.getColors.
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbluepandabear committed Jul 12, 2022
1 parent 285b8bc commit 62a13aa
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ fun Bitmap.getNumberOfUniqueColors(excludeTransparentPixels: Boolean = true): In

fun Bitmap.getColors(): MutableList<Int> {
val colors = mutableListOf<Int>()
val array = IntArray(size())

getPixels(array, 0, width, 0, 0, width, height)

iterate {
val colorAtPixel = getPixel(it)
for (i in array.indices) {
val color = array[i]

if (!colors.contains(colorAtPixel)) {
colors.add(colorAtPixel)
if (!colors.contains(color)) {
colors.add(color)
}
}

Expand Down

0 comments on commit 62a13aa

Please sign in to comment.