码迷,mamicode.com
首页 > 其他好文 > 详细

pallete

时间:2014-12-12 11:51:07      阅读:521      评论:0      收藏:0      [点我收藏+]

标签:android   style   http   io   ar   color   os   使用   sp   

OverView

public final class pallete 继承自 Object

            java.lang.Object

                |_android.supprot.v7.graphics.Palette

Palette从图像中提取突出的颜色,这样可以把色值赋给ActionBar、或者其他,可以让界面整个色调统一.  

    Palette这个类中提取以下突出的颜色:

        Vibrant  (有活力)

        Vibrant dark(有活力 暗色)

        Vibrant light(有活力 亮色)

        Muted  (柔和)

        Muted dark(柔和 暗色)

        Muted light(柔和 亮色)

这些都可以通过合适的getteer方法提取。

同步factory方法generate(Bitmap)和generate(Bitmap,int)可以用来创建实例。这些应该在一个后台线程中调用,最完美的就是加载图像的那个线程。有时候这是不可能的,所以异步factory方法也被提出:generateAsync(Bitmap, PaletteAsyncListener)和generateAsync(Bitmap, int, PaletteAsyncListener)。示例如下所示:

Pallete.generateAsync(bitmap,new Palette.PalleteAsyncListener(){
    public void onGenerates(Palette palette){
         //do something with colors ……
    }
});

方法列表

Nested Classes










interface Palette.PaletteAsyncListener Listener to be used with generateAsync(Bitmap, PaletteAsyncListener) or generateAsync(Bitmap, int, PaletteAsyncListener)  








class Palette.Swatch Represents a color swatch generated from an image‘s palette. 








Public Methods










boolean equals(Object o)

Compares this instance with the specified object and indicates if they are equal.











static Palette generate(Bitmap bitmap)

Generate a Palette from a Bitmap using the default number of colors.











static Palette generate(Bitmap bitmap, int numColors)

Generate a Palette from a Bitmap using the specified numColors.











static AsyncTask<BitmapVoidPalette> generateAsync(Bitmap bitmap, int numColors, Palette.PaletteAsyncListener listener)

Generate a Palette asynchronously.











static AsyncTask<BitmapVoidPalette> generateAsync(Bitmap bitmap, Palette.PaletteAsyncListener listener)

Generate a Palette asynchronously.











int getDarkMutedColor(int defaultColor)

Returns a muted and dark color from the palette as an RGB packed int.











Palette.Swatch getDarkMutedSwatch()

Returns a muted and dark swatch from the palette.











int getDarkVibrantColor(int defaultColor)

Returns a dark and vibrant color from the palette as an RGB packed int.











Palette.Swatch getDarkVibrantSwatch()

Returns a dark and vibrant swatch from the palette.











int getLightMutedColor(int defaultColor)

Returns a muted and light color from the palette as an RGB packed int.











Palette.Swatch getLightMutedSwatch()

Returns a muted and light swatch from the palette.











int getLightVibrantColor(int defaultColor)

Returns a light and vibrant color from the palette as an RGB packed int.











Palette.Swatch getLightVibrantSwatch()

Returns a light and vibrant swatch from the palette.











int getMutedColor(int defaultColor)

Returns a muted color from the palette as an RGB packed int.











Palette.Swatch getMutedSwatch()

Returns a muted swatch from the palette.











List<Palette.Swatch> getSwatches()

Returns all of the swatches which make up the palette.











int getVibrantColor(int defaultColor)

Returns the most vibrant color in the palette as an RGB packed int.











Palette.Swatch getVibrantSwatch()

Returns the most vibrant swatch in the palette.











int hashCode()

Returns an integer hash code for this object.











解释各方法

public static Pallete generate(Bitmap bitmap) 从Bitmap生成一个Pallete,使用默认的颜色个数

public static Pallete generate(Bitmap bitmap, int numColors) 从Bitmap生成Palette,使用指定的numColors。好的numColors值依图像源而定风景画一般取12-16之间,对于人脸占大部分的图取值24-32。numColors越大,计算所需的时间越长。

public boolean equals(Object o) 比较该实例与某个实例。默认只有当this == o 时结果是true,否则为false。为了equal,o必须代表与实例同样的对象使用一个类依赖对比。一般约定对比应该是反身的、对称而且可传递的。同时,没有对象引用除了null等于null。如果想实现自己的equals方法,可以参照https://developer.android.com/reference/java/lang/Object.html#writing_equals

public static AsyncTask<BitmapVoidPalettegenerateAsync (Bitmap bitmap, int numColors, Palette.PaletteAsyncListener listener)

Generate a Palette asynchronously. onGenerated(Palette) will be called with the created instance. The resultingPalette is the same as what would be created by calling generate(Bitmap, int).

Parameters
listener Listener to be invoked when the Palette has been generated.
Returns
  • the AsyncTask used to asynchronously generate the instance.

public static AsyncTask<BitmapVoidPalettegenerateAsync (Bitmap bitmap,Palette.PaletteAsyncListener listener)

Generate a Palette asynchronously. onGenerated(Palette) will be called with the created instance. The resultingPalette is the same as what would be created by calling generate(Bitmap).

Parameters
listener Listener to be invoked when the Palette has been generated.
Returns
  • the AsyncTask used to asynchronously generate the instance.

public int getDarkMutedColor (int defaultColor)

Returns a muted and dark color from the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

public Palette.Swatch getDarkMutedSwatch ()

Returns a muted and dark swatch from the palette. Might be null.

public int getDarkVibrantColor (int defaultColor)

Returns a dark and vibrant color from the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

public Palette.Swatch getDarkVibrantSwatch ()

Returns a dark and vibrant swatch from the palette. Might be null.

public int getLightMutedColor (int defaultColor)

Returns a muted and light color from the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

public Palette.Swatch getLightMutedSwatch ()

Returns a muted and light swatch from the palette. Might be null.

public int getLightVibrantColor (int defaultColor)

Returns a light and vibrant color from the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

public Palette.Swatch getLightVibrantSwatch ()

Returns a light and vibrant swatch from the palette. Might be null.

public int getMutedColor (int defaultColor)

Returns a muted(柔和的)color from the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

  public Palette.Swatch getMutedSwatch ()

Returns a muted swatch from the palette. Might be null.

public List<Palette.SwatchgetSwatches ()

Returns all of the swatches which make up the palette.

public int getVibrantColor (int defaultColor)

Returns the most vibrant color in the palette as an RGB packed int.

Parameters
defaultColor value to return if the swatch isn‘t available

public Palette.Swatch getVibrantSwatch ()

Returns the most vibrant swatch in the palette. Might be null.

public int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object‘s hash code.


pallete

标签:android   style   http   io   ar   color   os   使用   sp   

原文地址:http://my.oschina.net/liusicong/blog/355285

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!