pinguo-zhouwei/EasyBlur

blur优化

arvinljw opened this issue · 0 comments

如果bitmap是rgb565的,那么就会导致模糊花屏,可以转换成argb8888。

private static Bitmap rsBlur(Context context, Bitmap source, int radius, float scale) {
    Log.i(TAG, "origin size:" + source.getWidth() + "*" + source.getHeight());
    if (source.getConfig() != Bitmap.Config.ARGB_8888) {
        source = RGB565toARGB888(source);
    }
    //other code...
}
private static Bitmap RGB565toARGB888(Bitmap img) {
    int numPixels = img.getWidth() * img.getHeight();
    int[] pixels = new int[numPixels];
    //Get JPEG pixels.  Each int is the color values for one pixel.
    img.getPixels(pixels, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
    //Create a Bitmap of the appropriate format.
    Bitmap result = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.ARGB_8888);
    //Set RGB pixels.
    result.setPixels(pixels, 0, result.getWidth(), 0, 0, result.getWidth(), result.getHeight());
    return result;
}