切割多点ploygon出位图,并把它放在透明 [英] Cutting a multipoint ploygon out of Bitmap and placing it on transparency
问题描述
我有一个位图外面,我切了multipi点多边形。我很好奇的正确处理是用于取任意形状内的像素,并将它们拷贝到一个新的位图,其中的像素的其余部分是透明的。其目的是使用户能够跟踪形状,然后除去该多边形外一切
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
推荐答案
不知道如何你的code ++工程,但这里是如何做到这一点的想法:
Not sure how your code works, but here's an idea on how to do it:
- 计算所选区域(找分钟X,最小Y,最大x和最大Y点从点)的边框。
- 裁剪图像使用任何的边框的
位图
或画布
- 方法。 - 创建一个
路径
从你的观点,全部搬迁到新的位图(X- =其minX,Y = MINY)
; - 设置你的路径<一个href="http://developer.android.com/reference/android/graphics/Path.FillType.html"><$c$c>FillType$c$c>一个是反向(补外)。
- 在新的裁剪画布,画用油漆与Xfermode为<一个路径href="http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html"><$c$c>PorterDuff.CLEAR$c$c>,这将删除所有的颜色。
- Calculate the bounding rectangle of the selected area (find min x, min y, max x and max y from your points).
- Crop your image to the bounding rectangle using any of the
Bitmap
orCanvas
-methods. - Create a
Path
from your points, all moved into your new bitmap(x-=minX, y-=minY)
; - Set your Paths
FillType
to one that is inverse (fill the outside). - On your new cropped canvas, draw the Path using a paint with the Xfermode as
PorterDuff.CLEAR
, which removes all color.
这篇关于切割多点ploygon出位图,并把它放在透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!