1

我想在android中实现多点裁剪,如何裁剪路径线内的图像(如图所示的白线)?

我使用的代码是:

private Bitmap image;

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    ImageView iv = (ImageView) findViewById(R.id.imageView1);
    image = BitmapFactory.decodeResource(getResources(), R.drawable.splash);
    Bitmap resultingImage = Bitmap.createBitmap(image.getWidth(),
            image.getHeight(), image.getConfig());

    Canvas canvas = new Canvas(resultingImage);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeWidth(3);
    Path path = new Path();
    path.lineTo(150, 0);
    path.lineTo(210, 120);
    path.lineTo(150, 240);
    path.lineTo(70, 120);
    path.lineTo(150, 0);
    canvas.drawPath(path, paint);
    canvas.drawBitmap(resultingImage, 0, 0, paint);
    iv.setImageBitmap(resultingImage);
}

}

4

1 回答 1

0

这个想法是渲染一个路径并用位图填充它。

有关详细信息,请参阅此链接:http ://www.41post.com/4794/programming/android-rendering-a-path-with-a-bitmap-fill

于 2012-12-12T14:05:28.290 回答