是否有可能图像阵列添加到画布上,然后将其删除? [英] Is it possible to add an array of images to canvas and then delete them?

查看:107
本文介绍了是否有可能图像阵列添加到画布上,然后将其删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能图像阵列添加到画布上,然后删除单个图像?因此,可以说,我宣布一个ArrayList和我的图片添加到它。然后我画他们在canvas.How我可以只删除一个图像,而不是他们呢?这可能吗?

 的ArrayList<整数GT; myImageList =新的ArrayList<整数GT;();
myImageList.add(R.drawable.image1);
myImageList.add(R.drawable.image2);
myImageList.add(R.drawable.image3);
canvas.drawBitmap(myImageList [0],300,400,空);
canvas.drawBitmap(myImageList [1],300,400,空);
canvas.drawBitmap(myImageList [2],300,400,空);


解决方案

这是不可能的,因为一旦你画在画布上的任何图像的画布位图的像素值被改变。

您必须清除整个画布,再重新绘制在画布上的所有其它图像,

一种优化你能做的就是应用剪裁区域,在这种情况下不清除画布,并按照步骤:

 区域clip_region =图像(要删除)在画布上的区域;
canvas_object.cli pregion(clip_region);

现在清楚只有clip_region面积并绘制在画布上的所有其它图像,通过这种优化您的应用程序将需要更少的CPU绘制比没有剪辑区域绘制,

Is it possible to add an array of images to a canvas and then delete individual images?So lets say I declare an ArrayList and add my images to it. I then draw them on the canvas.How can i delete just one image instead of them all?Is this possible?

ArrayList<Integer> myImageList = new ArrayList<Integer>();
myImageList.add(R.drawable.image1);
myImageList.add(R.drawable.image2);
myImageList.add(R.drawable.image3);
canvas.drawBitmap(myImageList[0], 300, 400, null);
canvas.drawBitmap(myImageList[1], 300, 400, null);
canvas.drawBitmap(myImageList[2], 300, 400, null);

解决方案

It is not possible, Because once you have drawn any image on canvas the pixel value of the bitmap of that canvas is changed.

You have to clear the whole canvas and redraw all other images again on the canvas,

One optimization you can do is apply a clip region , in that case don't clear the canvas and follow the steps:

Region clip_region= region of the image(which you want to remove ) on the canvas;
canvas_object.clipRegion(clip_region);

Now clear only the clip_region area and draw all other images on the canvas, With this optimization your app will take less cpu to draw than drawing without CLIP REGION ,

这篇关于是否有可能图像阵列添加到画布上,然后将其删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆