Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

android - Cutting a multipoint ploygon out of Bitmap and placing it on transparency

I have a bitmap out of which I'm cutting out a multipi point polygon. I'm curious what the correct process is for taking the pixels within the arbitrary shape and copying them onto a new bitmap where the rest of the pixels are transparent. The objective is to allow the user to trace the shape and then remove everything outside the polygon.

I have the polygon part worked out (as a an array of points), but now am stumped as to how to transfer just the selected pixels to a new Bitmap.

TIA

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure how your code works, but here's an idea on how to do it:

  1. Calculate the bounding rectangle of the selected area (find min x, min y, max x and max y from your points).
  2. Crop your image to the bounding rectangle using any of the Bitmap or Canvas-methods.
  3. Create a Path from your points, all moved into your new bitmap (x-=minX, y-=minY);
  4. Set your Paths FillType to one that is inverse (fill the outside).
  5. On your new cropped canvas, draw the Path using a paint with the Xfermode as PorterDuff.CLEAR, which removes all color.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...