Skip to content

Methods allowing you to get the average color of a image by URL or bytes

License

Notifications You must be signed in to change notification settings

lukemansell/get-image-color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Get Average Image Color

Summary

This NuGet package contains methods allowing you to get the average color of an image by either passing through the bytes of the image, or passing through the URL of an image.

The rgba hex value is then returned (eg: #ff000088).

This is a work in progress and I'm open to ideas on how to increase the speed of this and also how well it calculates the average color.

Why I have written this

I needed to get the average color of images for Musicstax.

How to use

Once installing this package, there are two methods you can use:

GetImageColor.AverageFromUrl(string url, string defaultColor = DefaultColor)

GetImageColor.AverageFromBytes(byte[] imageBytes, string defaultColor = DefaultColor)

An example might be:

var averageColor = await GetImageColor.AverageFromUrl(url);

which will return a string, eg: #ffffffff

Exception handling

As you could pass through an invalid URL (or perhaps you don't have permission to view it), there is the possibility that an average color can not be calculated. In this case, by default #000000FF will be returned if the FromUrl method can not fetch the image. This is the color black.

You can override this default color by:

var averageColor = await GetImageColor.AverageFromUrl(url, "#FFFFFFFF);

Expanding

I am keen to expand this to get the most dominant color from an image, which will come soon.

About

Methods allowing you to get the average color of a image by URL or bytes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages