14

I want to learn how can I create layers (like in photoshop) in my android application. I want to achieve one basic thing: when I add an image in my canvas, which will be some figure for example, I want to be able to paint the canvas, but the painting must not effect the lines of figure. And then I need to save that image on my Sd card.

Any suggestions/advice/examples? What can I use to achieve this?

4

4 回答 4

1

你如何绘画的顺序构成了图层。创建一些您绘制的对象堆栈,然后修改单个对象(在图层中绘制)或在此堆栈中移动它们(更改图层)。使用相同的顺序创建要保存的图像。

于 2012-05-20T19:10:25.013 回答
1

画布中的图层。

    Bitmap bitmap=Bitmap.createBitmap(500,500, Bitmap.Config.ARGB_8888);
    Canvas canvas=new Canvas(bitmap);
    Paint paint_outer=new Paint();
    paint_outer.setColor(Color.parseColor("#DEB887"));
    paint_outer.setStrokeWidth(140);
    paint_outer.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(250,250,150,paint_outer);

    Paint paint_inner=new Paint();
    ComposePathEffect pathEffect=new ComposePathEffect(new CornerPathEffect(40),new DiscretePathEffect(60f,25f));
    paint_inner.setPathEffect(pathEffect);
    paint_inner.setColor(Color.parseColor("#8B4513"));
    paint_inner.setStrokeWidth(90);
    paint_inner.setStyle(Paint.Style.STROKE);
    canvas.drawCircle(250,250,150,paint_inner);
    iv.setImageBitmap(bitmap);
于 2019-03-07T00:31:52.883 回答
0

您可以在 FrameLayout 中组合图层。您可能需要一些技巧来确保将触摸事件传递到正确的层。

一旦你让 android 以你喜欢的方式组合你的视图,你可以 mFrameLayout.onDraw(Canvas c) 将整个东西绘制到画布上。

这篇文章有一些关于如何将你的视图组变成一个 jpeg 画布上的图像到 JPEG 文件的信息

于 2012-05-25T23:16:29.107 回答
0

Xfermode查看可以应用于的各种s PaintPorterDuff.Mode提供一些选项,就像您在 Photoshop 中获得的一样,例如,加网和乘法、变亮和变暗。然而,这AvoidXferMode可能更适合您的需求。

于 2012-05-20T20:35:39.563 回答