使位图触摸透明的特定区域 - >再次 [英] Make certain area of bitmap transparent on touch --> again

查看:136
本文介绍了使位图触摸透明的特定区域 - >再次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想达到相同的结果每个线程:
<一href=\"http://stackoverflow.com/questions/5368774/make-certain-area-of-bitmap-transparent-on-touch\">Make位图触摸透明的某些区域。
我坚持在这个答案psented code $ P $: LUMIS答案并acording到STED这个解决方案应该的工作。

I'm trying to achieve the same results as per thread: Make certain area of bitmap transparent on touch. I'm stick to code presented in this answer: Lumis answer and acording to SteD this solution should work.

不幸的是不工作,我(也为其他用户:<一href=\"http://stackoverflow.com/questions/7033443/make-certain-area-of-bitmap-transparent-on-touch-doesnt-works-its-draw-a-blac\">Make位图触摸透明的某些区域不工作,这是画一个黑圈),我刚开始黑圈。
我试过很多东西,但没有得到这个解决。制作背景透明根据建议,从第二个线程不作任何区别。

Unfortunately is not working for me (and also for another user: Make certain area of bitmap transparent on touch doesn't works, it's draw a black circle), I'm just getting black circle. I tried many things but not get this solve. Make background transparent as per suggestion from second thread do not make any difference.

经过多次实验,我发现透明度的工作,当我设置此

After many experiments I found that transparency is working, when I'm set this

android:theme="@android:style/Theme.Translucent"

在我的Andr​​oidManifest.xml中,我可以看到我的应用程序,即桌面下的一切。
我通过code多次去了,无法看到明显的错误,只是我想原因是因为这是Z次序,但不对位图和帆布不维护ž订单。 ž排序是通过在一定的顺序图(这是在此code正确的)进行。

in my AndroidManifest.xml I can see everything under my application i.e. desktop. I went through code many times and cant see obvious mistake, only reason I thinking is cause this is Z order, but bitmaps and canvas do not maintenance z orders. Z ordering is done by drawing in certain order (which is correct in this code).

这是Android code优化的一些奇怪的例子,或者说我缺少Android清单文件的东西吗?

Is this some strange example of optimisation in android code, or I'm missing something in android manifest file?

推荐答案

终于让我找到解决方案,它的工作:

Finally I found solution that's working:

@Override
public void onDraw(Canvas canvas){
    super.onDraw(canvas);

    //draw background
    canvas.drawBitmap(bgr, 0, 150, null);
    //copy the default overlay into temporary overlay and punch a hole in it                          
    c2.drawBitmap(overlayDefault, 0, 0, null); //exclude this line to show all as you draw
    c2.drawCircle(X, Y, 80, pTouch);
    //draw the overlay over the background
    //canvas.drawBitmap(overlay, 0, 0, null);

    Paint new_paint = new Paint(/*Paint.ANTI_ALIAS_FLAG*/);
    new_paint.setXfermode(new PorterDuffXfermode(Mode.SRC_ATOP));
    canvas.drawBitmap(overlay, 0, 0, new_paint);
}

但我不明白为什么在工作。我是研究这个源$ C ​​$ C xfermodes:<一href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Xfermodes.html\">android Xfermodes演示并根据这一形象: Xfermodes

这没有任何意义,除了这xfermode确保覆盖位图是绘制第二(Z顺序)豆和透明度来扮演。但Z次序应绘制顺序进行维护。

It not make any sense, apart that xfermode make sure that overlay bitmap is bean drawn second (Z order) and transparency came to play. But Z order should be maintained by drawing order.

如果有人有更好的想法如何解决这个问题,请分享你的知识。

If somebody have better idea how to solve this, please share your knowledge.

问候。

这篇关于使位图触摸透明的特定区域 - &GT;再次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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