Цветное растровое изображение Dodge Blend

1

У меня есть два растровых изображения topBitmap и bottomBitmap, и мне нужно смешать два растровых изображения с помощью цветного dodge в android. Я не мог найти цветную уловку в PorterDuffXfermode. Есть ли способ сделать это с ot без использования Canvas?

Пожалуйста, дайте мне знать, как смешивать два растровых изображения с использованием режима цветного доджиса в android. Спасибо заранее.

Теги:

2 ответа

3
Лучший ответ

Привет, я нашел этот метод откуда-то в SO post. Этот метод принимает два изображения и создает одно изображение, используя цветную доджу

public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) {
            Bitmap base = source.copy(Config.ARGB_8888, true);
            Bitmap blend = layer.copy(Config.ARGB_8888, false);

            IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
            base.copyPixelsToBuffer(buffBase);
            buffBase.rewind();

            IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
            blend.copyPixelsToBuffer(buffBlend);
            buffBlend.rewind();

            IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
            buffOut.rewind();

            while (buffOut.position() < buffOut.limit()) {

                int filterInt = buffBlend.get();
                int srcInt = buffBase.get();

                int redValueFilter = Color.red(filterInt);
                int greenValueFilter = Color.green(filterInt);
                int blueValueFilter = Color.blue(filterInt);

                int redValueSrc = Color.red(srcInt);
                int greenValueSrc = Color.green(srcInt);
                int blueValueSrc = Color.blue(srcInt);

                int redValueFinal = colordodge(redValueFilter, redValueSrc);
                int greenValueFinal = colordodge(greenValueFilter, greenValueSrc);
                int blueValueFinal = colordodge(blueValueFilter, blueValueSrc);


                int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal);


                buffOut.put(pixel);
            }

            buffOut.rewind();

            base.copyPixelsFromBuffer(buffOut);
            blend.recycle();

            return base;
        }

вот этот метод действительно получить цвет уклонения для пикселя, чтобы получить эффект

private int colordodge(int in1, int in2) {
            float image = (float)in2;
            float mask = (float)in1;
            return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8 ) / (255 - image)))));
        }

Я пытаюсь создать изображение эскиза оригинальной фотографии, используя этот метод, я могу создать мультяшное изображение в полном полноформатном формате, но мне нужно в черно-белом карандашном эскизном формате. Если у вас есть идеи, пожалуйста, поделитесь им.

надеюсь, что эти методы вам полезны

1

Поместите этот код для эскиза карандаша, эта работа для меня

public Bitmap Changetosketch(Bitmap bmp) {
    Bitmap Copy, Invert, Result;
    Copy = toGrayscale(bmp);
    Invert = createInvertedBitmap(Copy);
    Invert = Blur.blur(this, Invert);
    Result = ColorDodgeBlend(Invert, Copy);
    return Result;
}
public static Bitmap toGrayscale(Bitmap src)
{
    final double GS_RED = 0.299;
    final double GS_GREEN = 0.587;
    final double GS_BLUE = 0.114;

    // create output bitmap
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    // pixel information
    int A, R, G, B;
    int pixel;

    // get image size
    int width = src.getWidth();
    int height = src.getHeight();

    // scan through every single pixel
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            // get one pixel color
            pixel = src.getPixel(x, y);
            // retrieve color of all channels
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            // take conversion up to one single value
            R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);
            // set new pixel color to output bitmap
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }

    // return final image
    return bmOut;
}

public static Bitmap createInvertedBitmap(Bitmap src) {
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig());
    // color info
    int A, R, G, B;
    int pixelColor;
    // image size
    int height = src.getHeight();
    int width = src.getWidth();

    // scan through every pixel
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            // get one pixel
            pixelColor = src.getPixel(x, y);
            // saving alpha channel
            A = Color.alpha(pixelColor);
            // inverting byte for each R/G/B channel
            R = 255 - Color.red(pixelColor);
            G = 255 - Color.green(pixelColor);
            B = 255 - Color.blue(pixelColor);
            // set newly-inverted pixel to output image
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}
public Bitmap ColorDodgeBlend(Bitmap source, Bitmap layer) {
    Bitmap base = source.copy(Bitmap.Config.ARGB_8888, true);
    Bitmap blend = layer.copy(Bitmap.Config.ARGB_8888, false);

    IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
    base.copyPixelsToBuffer(buffBase);
    buffBase.rewind();

    IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
    blend.copyPixelsToBuffer(buffBlend);
    buffBlend.rewind();

    IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
    buffOut.rewind();

    while (buffOut.position() < buffOut.limit()) {

        int filterInt = buffBlend.get();
        int srcInt = buffBase.get();

        int redValueFilter = Color.red(filterInt);
        int greenValueFilter = Color.green(filterInt);
        int blueValueFilter = Color.blue(filterInt);

        int redValueSrc = Color.red(srcInt);
        int greenValueSrc = Color.green(srcInt);
        int blueValueSrc = Color.blue(srcInt);

        int redValueFinal = colordodge(redValueFilter, redValueSrc);
        int greenValueFinal = colordodge(greenValueFilter, greenValueSrc);
        int blueValueFinal = colordodge(blueValueFilter, blueValueSrc);


        int pixel = Color.argb(255, redValueFinal, greenValueFinal, blueValueFinal);


        buffOut.put(pixel);
    }

    buffOut.rewind();

    base.copyPixelsFromBuffer(buffOut);
    blend.recycle();

    return base;
}

private int colordodge(int in1, int in2) {
    float image = (float)in2;
    float mask = (float)in1;
    return ((int) ((image == 255) ? image:Math.min(255, (((long)mask << 8 ) / (255 - image)))));
}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню