سؤال

Help me realized some logic. I have a picture which redrawing by:

public void onClick(View v) {
        BitmapDrawable mydrawable = (BitmapDrawable) imageView.getDrawable();
        Bitmap b = mydrawable.getBitmap();
        b = doHighlightImage(b);
        imageView.setImageBitmap(b);
    }
});

public static Bitmap doHighlightImage(Bitmap src) {
    // создадим новый битмап, который станет итоговым
    Bitmap bmOut = Bitmap.createBitmap(src.getWidth() + 96,
            src.getHeight() + 96, Bitmap.Config.ARGB_8888);
    // подключаем холст
    Canvas canvas = new Canvas(bmOut);
    // установим цвет по умолчанию
    canvas.drawColor(0, PorterDuff.Mode.CLEAR);

    // создадим размытие для прозрачности
    Paint ptBlur = new Paint();
    ptBlur.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
    int[] offsetXY = new int[2];
    // получим прозрачный слепок из изображения
    Bitmap bmAlpha = src.extractAlpha(ptBlur, offsetXY);
    // готовимся к рисованию
    Paint ptAlphaColor = new Paint();
    ptAlphaColor.setColor(0xFFFFFFFF);
    // закрашиваем цветом цветной слепок (bitmap)
    canvas.drawBitmap(bmAlpha, offsetXY[0], offsetXY[1], ptAlphaColor);
    // освобождаем ресурсы
    bmAlpha.recycle();

    // рисуем исходник
    canvas.drawBitmap(src, 0, 0, null);

    // возвращаем финальный рисунок
    return bmOut;
}

But, after redrawing i must return the initial state of the picture. How to do this?

هل كانت مفيدة؟

المحلول

What do you mean by must return the initial state of the picture? Bitmap is immutable, so just keep a reference to whatever bitmap you need and don't worry about changing it - it's impossible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top