What is the replacement of Android.Support.V7.Graphics.palette in Maui world

khatauli 61 Reputation points
2024-07-26T16:13:10.8666667+00:00

Hi Maui experts, I have a following piece of code in Xamain app, which I want to port over to Maui, but don't seem to find the alternative. The intent is to extract the main theme color from the bitmap image. Any ideas?

palette = Android.Support.V7.Graphics.Palette.From(bitmap).Generate();
var swatch = palette.VibrantSwatch;
var color = swatch.Rgb;
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,487 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 42,426 Reputation points Microsoft Vendor
    2024-07-29T02:41:11.29+00:00

    Hello,

    It's an Android question. Current Android API are available to Maui apps at the .Net for Android level, the same way they were available to Xamarin apps via Xamarin.Android. The Support Library Packages has been deprecated. It has been replaced with JetPack libraries in AndroidX:

    Note: With the release of Support Library 28.0.0, the android.support-packaged libraries are deprecated and replaced by individually-versioned Jetpack libraries packaged as androidx. The initial 1.0.0 release of the Jetpack libraries provides parity with Support Library 28.0.0 and provides a starting point for migrating to the new androidx packaging. AndroidX bindings are available for .Net for Android apps. You could find the Palette package at Nuget Gallery | Xamarin.AndroidX.Palette. Although the name of this package includes Xamarin, it can already run on the .Net for Android platform.

    In addition, after testing, the latest version of the package on the MAUI platform will cause an error. The version number that can be used in MAUI is 1.0.0.19. Android Palette documentation is available at: Palette | JetPack | Android Developers Because this is Android specific code you will need to call it from an Android only block. See Invoking Platform Code for more information.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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