ksemenenko / colorthief Goto Github PK
View Code? Open in Web Editor NEWColor Thief for .NET
License: MIT License
Color Thief for .NET
License: MIT License
Hi!
Just asking, is this package already finished?
I would love to use it...
Lots of Greetings!
Volker
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
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?
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:
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)
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
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.
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?
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);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.