Giter Site home page Giter Site logo

colorthief's People

Contributors

anaghsharma avatar ksemenenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colorthief's Issues

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile? File name: 'ColorThief.Forms.dll'

Hi, I get this error in Xamarin.Forms 3 .net Standard 2 project, What should I do?

Severity Code Description Project File Line Suppression State
Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'ColorThief.Forms.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) ColorThiefDemo.Android

Exception = {"Could not load file or assembly 'System.Runtime.WindowsRuntime, Version=4.0.11.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.

I get the above exception when I add the latest NuGet version to a fresh UWP project, and when I do .GetPalette().

My test code:

private async void Go()
{
string URL = "https://content.linkedin.com/content/dam/brand/site/img/color/color-palette-order.png";
Windows.Storage.Streams.IRandomAccessStream random = await Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(URL)).OpenReadAsync();
Windows.Graphics.Imaging.BitmapDecoder decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(random);

        ColorThief.ColorThief la = new ColorThief.ColorThief();
        List<QuantizedColor> colors = await la.GetPalette(decoder, 30, 10, false);

        foreach (QuantizedColor c in colors)
        {
            Rectangle rect = new Rectangle();
            rect.Width = 50;
            rect.Height = 50;

            Windows.UI.Color clr = new Windows.UI.Color() { A = c.Color.A, R = c.Color.R, B = c.Color.B, G = c.Color.G };
            rect.Fill = new SolidColorBrush(clr);
            gridView.Children.Add(rect);
        }
    }

Any thoughts?

GetPalette gives smaller or bigger palette than asked

For example:
if I call GetPalette and, let say, ask for 10 colors, it can give me 9.
And if I ask for 2 colors, it can give me 3 or 4.

for now I'm solving it by two ways:

  • count++ till asked count satisfy
  • making big palette and take first(count) colors

Setting quality to 0 throws IndexOutOfRangeException

Good job, @KSemenenko! Thanks for doing this.

In the original js version of colorthief, the highest quality setting is 1. According to your code comments (example here), the highest quality setting in your ported version is 0. However, passing in 0 throws an IndexOutOfRangeException from GetPixelsFast.

I suggest correcting the code comments and adding a guard clause similar to the original here.

(I'll be happy to send a pull request)

Need a update to ColorThief to use the latest Xamarin.Forms and also to use .net standard 2.1

Hello,
I am running into issues in trying to use ColorThief with Xamarin.Forms 5.0.0.2337. The Android libraries (I am not sure about ios) that the currently used by ColorThief are not compatable with the latest Android libraries that are required for Xamarin.Forms 5.0+. I am also seeing issues with the ColorThief.NetStandard.v20 project. Some of the newer C# language features are causing issues with this project. If it was updated to use .net standard 2.1 it would solve them.

Thanks.
---Dave

Color Order In GetPalette

only on Xamarin.forms nuget package:
//var pal = _colorThief.GetPalette(pictureBoxSpectrum.Image, 6, 10, false).ToList();
all the colors are correct, but Red and Blue color Bytes are swapped.
I was porting an app from windows forms app to Xamarin iOS, and noticed that all the colors are not the same, after some investigation turns out only instead of using RGB of your values, used them as BGR.

Error CS0012: The type 'QuantizedColor' is defined in an assembly that is not referenced. You must add a reference to assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'.

Hi @KSemenenko

I'm trying to follow your suggestion in the prior issue:

create proxy for ColorThief platform specific implementation using Xamarin Forms DependencyService.

In my PCL Xamarin project I have an interface and added reference to ksesmenenko.ColorThief.Forms v1.0.0.4:

using ColorThiefDotNet;
...
public interface IColorThiefHelper
{
    List<QuantizedColor> GetPalette(string sourceImage, int colorCount);
    QuantizedColor GetColor(string sourceImage);
}

and then also in my PCL Xamarin project call it using dependency service:

var colorTask = DependencyService.Get<IColorThiefHelper>().GetPalette(Logo, 8);
var backgroundColor = Color.FromHex(colorTask.FirstOrDefault().Color.ToHexString());
var foregroundColor = Color.FromHex(colorTask.LastOrDefault().Color.ToHexString());
BackgroundColor = backgroundColor;
TextInverseColor = foregroundColor;

Finally in my iOS project I have added reference to ksesmenenko.ColorThief.Forms v1.0.0.4 again and then made the dependency service implementation like so:

[assembly: Dependency(typeof(ColorThiefHelper))]
namespace IOSNameSpace
{
    public class ColorThiefHelper : IColorThiefHelper  {
        private ColorThief Thief { get; set; }
        public ColorThiefHelper()
        {
            Thief = new ColorThief();
        }    

        static UIImage FromUrl(string uri)
        {
            using (var url = new NSUrl(uri))
            using (var data = NSData.FromUrl(url))
                return UIImage.LoadFromData(data);
        }    

        public List<QuantizedColor> GetPalette(string sourceImage, int colorCount)
        {
            UIImage image = FromUrl(sourceImage);
            return Thief.GetPalette(image,colorCount,10,true);
        }
        public QuantizedColor GetColor(string sourceImage)
        {
            UIImage image = FromUrl(sourceImage);
            return Thief.GetColor(image, 10, true); 
        }
}

And here I get the error on the ColorThiefHelper class :

Error CS0012: The type 'QuantizedColor' is defined in an assembly that is not referenced. You must add a reference to assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'. (CS0012)

The bug is strange as there is no Version=1.1.0.1 of ColorThief.Forms in nuget.

Do you know what might be the problem?

Exception = {"(expectedDataLength = 9216000) != (pixels.length = 18432000)"}

I'm getting the above error when using the source package hosted here, or NuGet package 1.0.0. This is for every image.

FileOpenPicker fileOpenPicker = new FileOpenPicker();
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
fileOpenPicker.FileTypeFilter.Add(".jpg");
fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;

        var inputFile = await fileOpenPicker.PickSingleFileAsync();

        if (inputFile == null)
        {
            // The user cancelled the picking operation
            return;
        }

        SoftwareBitmap softwareBitmap;

        using (IRandomAccessStream stream = await inputFile.OpenAsync(FileAccessMode.Read))
        {
            // Create the decoder from the stream
            BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

            // Get the SoftwareBitmap representation of the file
            softwareBitmap = await decoder.GetSoftwareBitmapAsync();

            var colorThief = new ColorThief.ColorThief();
            List<QuantizedColor> colors = await colorThief.GetPalette(decoder, 8);

}

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.