是否可以将一组图像添加到画布然后删除它们? [英] Is it possible to add an array of images to canvas and then delete them?

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

问题描述

是否可以将一组图像添加到画布然后删除单个图像?假设我声明了一个 ArrayList 并将我的图像添加到其中.然后我把它们画在画布上.我怎样才能只删除一张图片而不是全部?这可能吗?

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);

现在只清除 clip_region 区域并在画布上绘制所有其他图像,通过这种优化,您的应用程序将比没有 CLIP REGION 的情况下绘制更少的 cpu ,

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天全站免登陆