繁体   English   中英

排列在画布上绘制的可绘制对象

[英]Arranging drawables drawn on canvas

在重新绘制之前,有没有办法在画布上安排可绘制的绘制? 我的意思是设置哪些 drawable 将在前面绘制,哪些 drawable 将在后面绘制。

它们是按照您绘制的顺序绘制的。 试着先画坐在后面的那个,最后画前面的。

一种方法是让您绘制的所有内容定义一个 z-index 变量,并收集您在一个点绘制的所有内容并将它们放在一个列表中,然后在绘制之前按 z-index 排序。

前任:

Interface IDrawable{
   int getZ();
   void draw();
}

class drawMe implements IDrawable{
    @overrider
    draw(){
    /// do my drawing
    }

    @override
    int getZ() {return z; }
}

在你的绘画或主课中

List<IDrawable> myList= new ArrayList();
myList.Add(new DrawMe());

并在您的绘制方法中

for(IDrawable draw : myList.OrderBy(z){
   draw.draw();
}

反正就是这个概念

您可以绘制到临时画布,以便稍后绘制到主画布。

Picture iconFrame = new Picture();
Canvas tempCanvas = iconFrame.beginRecording(width, height);
// width and height refer to the intended destination canvas size

...
// Any configuration before performing the draw should be done here

tempCanvas.drawPath(...);
tempCanvas.drawBitmap(...);
// Any required draw commands for this image should be done to tempCanvas

iconFrame.endRecording();

...
// Any other configuration or draw commands can be done here

iconFrame.draw(canvas);
// Assigns the content of tempCanvas to the top of the main Canvas

就我而言,在自定义路径中对我的图像进行的 PorterDuff 操作仅在首先完成时才有效,因为后来的绘制会损坏它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM