简体   繁体   English

用位图重画后如何返回图片

[英]how return picture after after redraw with Bitmap

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 ? 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM