Skip to content

CPU spikes when calling async method  #95

@sidster-io

Description

@sidster-io

Using UIImageColor to get the dominant color on the photo to set background accordingly but when I do try the following

WebImage(url: URL("https://img-9gag-fun.9cache.com/photo/aQ1GWV8_700b.jpg"))
                 .onSuccess { image, cacheType in
                            image.getColors(quality: .lowest) {colors in
                                guard let colors = colors else { return }
                                if (colors.background.toHexString() != "#000000") {
                                    self.cardBackground = colors.background
                                } else {
                                    self.cardBackground = UIColor(red: 0.130, green: 0.130, blue: 0.130, alpha: 1.0)
                                }
                                self.cardHeading = colors.primary
                                self.cardDesc = colors.secondary
                            }
                    }

Before I using WebImage I had

Image.init(uiImage: imageData)
           .onAppear(perform: {
                            image.getColors(quality: .lowest) { colors in
                                guard let colors = colors else { return }
                                if (colors.background.toHexString() != "#000000") {
                                    self.cardBackground = colors.background
                                } else {
                                    self.cardBackground = UIColor(red: 0.130, green: 0.130, blue: 0.130, alpha: 1.0)
                                }
                                self.cardHeading = colors.primary
                                self.cardDesc = colors.secondary
                            }
                        }) 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions