how to use image color for using in ui

IKINGSHADOW 136 Reputation points
2022-06-16T13:28:43.477+00:00

hello everyone ,
so, I have a music player project and in my project i want to use musics image dominant (or Correct) color for using in my UI , i searched about it a lot but i couldn't find any good solution , in fact i want to make something like this :

212117-screenshot-20220616-174854-comandroidvending.jpg

212132-screenshot-20220616-174838-comandroidvending.jpg212056-screenshot-20220616-174849-comandroidvending.jpg

but i really don't know how should i do this ( i found some libraries like color thief but i didn't get any good result ) ,
so could you help me to find solution please ???

Developer technologies | Windows Presentation Foundation
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 48,711 Reputation points Microsoft External Staff
    2022-06-17T08:20:37.523+00:00

    Hi,@IKINGSHADOW . Welcome Microsoft Q&A.

    You could try to refer to the example below and see if it helps you.
    Xaml:

    <Window.Resources>  
            <local:StringToImageConverter x:Key="StringToImageConverter" />  
        </Window.Resources>  
        <Grid>  
            <Grid.Background>  
                <ImageBrush ImageSource="{Binding ElementName=lb,Path=SelectedItem.Name, Converter={StaticResource StringToImageConverter}}"/>  
            </Grid.Background>  
            <Grid.ColumnDefinitions>  
                <ColumnDefinition Width="60"/>  
                <ColumnDefinition/>  
            </Grid.ColumnDefinitions>  
              <ListView HorizontalAlignment="Left" x:Name="lb" Width="50" Height="100" ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}"  >  
                <ListView.ItemTemplate>  
                    <DataTemplate>  
                        <StackPanel >  
                            <Image Width="30" Source="{Binding Name, Converter={StaticResource StringToImageConverter}}" />  
                        </StackPanel>  
                    </DataTemplate>  
                </ListView.ItemTemplate>  
            </ListView>  
            <Image Grid.Column="1" Width="100" Height=" 100" VerticalAlignment="Bottom" Margin="20"  
                   Source="{Binding ElementName=lb,Path=SelectedItem.Name, Converter={StaticResource StringToImageConverter}}"/>  
        </Grid>  
    

    Codebehind:

    212350-new-text-document-2.txt

    The result:
    212454-8.gif


    If the response is helpful, please click "Accept Answer" and upvote it.
     Note: Please follow the steps in our [documentation][5] to enable e-mail notifications if you want to receive the related email notification for this thread. 

    [5]: https://learn.microsoft.com/en-us/answers/articles/67444/email-notifications.html

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.