在Android中有效更改位图颜色/色相

问题描述 投票:1回答:1

我正在使用以下方法来更改位图的色调:

public Bitmap changeHue( Bitmap source, double hue ) {

    Bitmap result = Bitmap.createBitmap( screenWidth, screenHeight, source.getConfig() );

    float[] hsv = new float[3];
    for( int x = 0; x < source.getWidth(); x++ ) {
        for( int y = 0; y < source.getHeight(); y++ ) {
            int c = source.getPixel( x, y );
            Color.colorToHSV( c, hsv );
            hsv[0] = (float) ((hsv[0] + 360 * hue) % 360);
            c = (Color.HSVToColor( hsv ) & 0x00ffffff) | (c & 0xff000000);
            result.setPixel( x, y, c );
        }
    }

    return result;
}

它可以完美工作并保持位图的亮度。但是,当更改位图大小为800 * 480或更高的色相时,此方法非常慢。如何在不损失太多图像质量的情况下对其进行优化?

android colors bitmap hsv hsl
1个回答
0
投票
如果将位图包装在ImageView中,则有一种非常简单的方法:

ImageView circle = new ImageView(this); circle.setImageBitmap(yourBitmap); circle.setColorFilter(Color.RED);

© www.soinside.com 2019 - 2024. All rights reserved.