将部分Android位图绘制到自身并重叠一些是否安全?

时间:2010-05-25 16:12:31

标签: android

我在我的摩托罗拉Droid上测试了它,它按预期工作。但是,我担心这可能是:

  1. 非常低效。
  2. 不保证可以在所有Android手机上使用。
  3. 代码:

    /* Create a simple 100 by 100 bitmap */
    Bitmap myBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    
    /* Create a canvas with which to draw on my bitmap */
    Canvas myCanvas = new Canvas(myBitmap);
    
    /* Draw a subset of my bitmap onto itself, with the source rectangle and destination rectangle overlapping */
    Rect sourceRect = new Rect(10, 0, 99, 99);
    Rect destRect = new Rect(0, 0, 89, 99);
    myCanvas.drawBitmap(myBitmap, sourceRect, destRect, null);
    

    正如我所说,这似乎在我的测试中运行良好,但是当在其他平台上执行位blits时,我并不总是能够保证将一个grpahics区域复制到安全,内存和性能方面。当源和目的地相交时,另一个。

    我欢迎任何有关此事的见解。

1 个答案:

答案 0 :(得分:0)

It should be perfectly safe. As for intersection - what could be wrong? If you are copying to region which you have copy from then it depends on implementation including your code. Worst (actually best) scenario is when it is copied byte by byte and you will have prefect "zebra" replication of your region where strip is the difference between source and destination regions. However, since most IO operations even in memory are buffered then your zebra will probably have interference of buffer/strip discrepancy. Which could be a little funny because of buffer, strip size and actual location of the region in the memory.

In other words it may look like image in kaleidoscope but it's perfectly safe.