Skip to content

Commit 62a13aa

Browse files
author
therealbluepandabear
committed
Utilized getPixels for Bitmap.getColors.
1 parent 285b8bc commit 62a13aa

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

app/src/main/java/com/therealbluepandabear/pixapencil/extensions/BitmapExtensions.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ fun Bitmap.getNumberOfUniqueColors(excludeTransparentPixels: Boolean = true): In
6161

6262
fun Bitmap.getColors(): MutableList<Int> {
6363
val colors = mutableListOf<Int>()
64+
val array = IntArray(size())
65+
66+
getPixels(array, 0, width, 0, 0, width, height)
6467

65-
iterate {
66-
val colorAtPixel = getPixel(it)
68+
for (i in array.indices) {
69+
val color = array[i]
6770

68-
if (!colors.contains(colorAtPixel)) {
69-
colors.add(colorAtPixel)
71+
if (!colors.contains(color)) {
72+
colors.add(color)
7073
}
7174
}
7275

0 commit comments

Comments
 (0)