【问题标题】:Is it possible to add an array of images to canvas and then delete them?是否可以将一组图像添加到画布然后删除它们?
【发布时间】:2013-01-11 23:29:34
【问题描述】:

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

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

【问题讨论】:

  • 您的意思是从画布上“删除”它们,还是从 ArrayList 中删除它们?
  • 我的意思是从画布上单独删除它们。
  • 绘制后,没有真正的“图像”概念。如果要擦除已经存在的像素,则必须清除画布。参考:stackoverflow.com/questions/7110555/…

标签: android bitmap arraylist android-canvas


【解决方案1】:

这是不可能的,因为一旦你在画布上绘制了任何图像,该画布的位图的像素值就会改变。

你必须清除整个画布并在画布上重新绘制所有其他图像,

您可以做的一个优化是应用一个剪辑区域,在这种情况下不要清除画布并按照以下步骤操作:

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,

【讨论】:

    猜你喜欢
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2016-10-18
    • 1970-01-01
    • 2019-01-14
    相关资源
    最近更新 更多