Giter Club home page Giter Club logo

kesa2773 / uiimagecolorpalette Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 11 KB

UIImageColorPalette is a versatile utility for extracting the prominent colors from images in iOS. It efficiently identifies and provides the three most prevalent colors in a UIImage.

License: MIT License

Objective-C 100.00%
clustering-algorithms color-analysis color-palette computer-vision graphics-programming image-processing image-rendering ios-development objective-c uicolor uiimage

uiimagecolorpalette's Introduction

UIImageColorPalette

UIImageColorPalette is a versatile utility for extracting the prominent colors from images in iOS. It efficiently identifies and provides the three most prevalent colors in a UIImage.

Table of Contents

Installation

To install UIImageColorPalette, follow these steps:

  1. Download: Download the UIImageColorPalette.h and UIImageColorPalette.m files.

  2. Add to project: Integrate the downloaded files into your project.

  3. Import the Class: Import the class wherever you want to use it:

#import "UIImageColorPalette.h"

Quick Start

Here are quick examples of how to use UIImageColorPalette to extract the color palette from an image:

Example 1: Using a local image file

// Load an image
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

// Retrieve the color palette
UIImageColorPalette *palette = [image retrieveColorPaletteWithQuality:UIImageResizeQualityStandard];
if (palette) {
    NSLog(@"Color Palette: %@", palette);
} else {
    NSLog(@"Failed to retrieve color palette.");
}

// Set the background color of view
UIColor *backgroundColor = palette.primary;
self.view.backgroundColor = backgroundColor;

// Set the text color for a label
UIColor *textColor = palette.secondary;
myLabel.textColor = textColor;

Example 2: Using a remote image URL

// Load an image from a remote URL
NSURL *imageURL = [NSURL URLWithString:@"https://example.com/image.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];

// Retrieve the color palette
UIImageColorPalette *palette = [image retrieveColorPaletteWithQuality:UIImageResizeQualityStandard];
if (palette) {
    NSLog(@"Color Palette: %@", palette);
} else {
    NSLog(@"Failed to retrieve color palette.");
}

Example 3: Asynchronous retrieval

// Load an image from a remote URL asynchronously
NSURL *imageURL = [NSURL URLWithString:@"https://example.com/image.jpg"];
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage *image = [UIImage imageWithData:imageData];
    
    [image retrieveColorPaletteWithQuality:UIImageResizeQualityStandard completion:^(UIImageColorPalette *palette) {
        if (palette) {
            NSLog(@"Color Palette: %@", palette);
        } else {
            NSLog(@"Failed to retrieve color palette.");
        }
    }];
});

Example 4: Customizing the resize quality

You can use other presets besides UIImageResizeQualityStandard by using the following options:

  • UIImageResizeQualityLow: Use low-quality resizing algorithm.
  • UIImageResizeQualityMedium: Use medium-quality resizing algorithm.
  • UIImageResizeQualityHigh: Use high-quality resizing algorithm.
// Load an image
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];

// Retrieve the color palette with custom resize quality
UIImageColorPalette *palette = [image retrieveColorPaletteWithQuality:UIImageResizeQualityHigh];
if (palette) {
    NSLog(@"Color Palette: %@", palette);
} else {
    NSLog(@"Failed to retrieve color palette.");
}

License

This project is licensed under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.