Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android & cut (remove) shape from bitmap

How do you cut (remove) a section from a bitmap??? I want that section/shape to be removed.. leave transparent in place of section.. Say shape is cercle or square..

enter image description here

enter image description here

like image 557
pulancheck1988 Avatar asked Aug 01 '12 19:08

pulancheck1988


People also ask

Whats Android means?

: a mobile robot usually with a human form. sci-fi androids.

Is Android better than Apple?

Generally, though, iOS devices are faster and smoother than most Android phones at comparable price ranges. For example, an iPhone 14 can perform nearly as well as the highest-end iPhone, and it starts at $799 MSRP. Even the budget iPhone SE is a great performer.

What Android is used for?

The Android operating system is a mobile operating system that was developed by Google (GOOGL​) to be primarily used for touchscreen devices, cell phones, and tablets.

Is Android owned by Google?

Android Inc., was bought by the American search engine company Google Inc., in 2005. At Google, the Android team decided to base their project on Linux, an open source operating system for personal computers.


1 Answers

You should be able do this with a Porter-Duff color filter and a Canvas:

public void punchHole(Bitmap bitmap, float cx, float cy, float radius) {
    Canvas c = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new PorderDuffColorFilter(0, PorderDuff.Mode.CLEAR));
    c.drawCircle(cx, cy, radius, paint);
}

Well, that was wrong. However, using a Porter-Duff transfer mode does work:

public void punchHole(Bitmap bitmap, float cx, float cy, float radius) {
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    canvas.drawCircle(cx, cy, radius, paint);
}

(The bitmap passed as an arg needs to be modifiable, of course.)

like image 182
Ted Hopp Avatar answered Oct 13 '22 10:10

Ted Hopp