简体   繁体   中英

Android: How to draw over downloaded bitmap and then populate it to ImageView?

My application is downloading a bitmap which is later populated into custom ImageView. However I want this bitmap to be updated before it is actually drawn on a canvas (I want to add some points over it). However as the result I see only populated bitmap without changes I made. Can anyone help?

Here is my onDraw method. "bitmap" object is set via setImageBitmap received from AsyncTask in onPostExecute() method.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (bitmap != null) {
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int padding = (width - bitmap.getWidth()) / 2;

        canvas.drawBitmap(bitmap, padding, 0, null);

        paint.setColor(Color.RED);
        paint.setStrokeWidth(5f);
        for (Face face : getPhotoObject().getFaces()) {
            canvas.drawPoint(face.getLeftEye().x, face.getLeftEye().y, paint);
            canvas.drawPoint(face.getRightEye().x, face.getRightEye().y, paint);
        }
    }
}

You can create a canvas with a bitmap at any time:

Canvas canvas = new Canvas(myBitmap);
// draw code
// the resulting bitmap will be edited.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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