图像获取像素化,当屏幕被触摸 [英] Images get pixelated when the screen is touched

查看:127
本文介绍了图像获取像素化,当屏幕被触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个小游戏在HTML / JS在Android上。我快到我的HTC Desire(Android 2.2的)的问题。当我触摸屏幕,所有的图像看起来是像素化,他们得到的未像素化的触摸结束时。

I'm building a little game in HTML/JS on Android. I'm running into a problem on my HTC Desire (Android 2.2). When I touch the screen, all the images look pixelated and they get un-pixelated when the touch ends.

下面是截图:

在右侧是当屏幕被触摸。有人可以帮我找出是什么导致这个问题呢?

On the right it's when the screen is being touched. Can someone help me figure out what's causing this issue?

注:

  • 在动画没有问题,如果屏幕不触及
  • 在我没有这个问题,在我的LG 540的Andr​​oid 2.1
  • 似乎图像得到的颜色数量有限时,它的被感动
  • 在我使用的PhoneGap

推荐答案

据我所知道的,说:像素化的行为是滚动(在升级Froyo及以上)做了优化。如果渲染简化,它使事情像一扔滚动动画需要较少的处理。

As far as I can tell, that "pixelated" behavior is an optimization made for scrolling (in Froyo and above). If the rendering is simplified, it makes things like the fling scroll animation require less processing.

如果您需要完整的浏览器功能,我不知道你能帮助它了。

If you need full browser functionality, I'm not sure you can help it much.

既然你说你正在做一个游戏,但是,我可能有一个解决办法。我希望你的游戏并不需要滚动(一个全屏幕),所以滚动优化是没有必要的。

Since you've said you're making a game, however, I might have a workaround. I'm hoping your game doesn't need scroll (one full screen), so the scrolling optimization isn't necessary.

我已经做了的WebView一个简单的测试。自来水,正如你所说,渲染得到简化,事情看起来有点过。然后,一旦东西被点击(web视图是没有更多的滚动正在发生),事情恢复正常。

I've done a simple test with a WebView. On tap, as you mentioned, the rendering gets simplified, and things look a little off. Then once something is clicked (the WebView knows no more scrolling is taking place), things go back to normal.

我通过更换一个web视图,用的FrameLayout修改我的布局。该的FrameLayout包含了web视图和一个看不见的按钮(在上面)。这个按钮抓住所有的触摸事件。于是,我选择选择什么类型的事件的WebView应该需要的,并传递给web视图。如果触摸和触摸起来发生并拢,用在betweeen没有运动,没有理由滚动,所以我还没有看到任何的像素化的行为。

I modified my Layout by replacing a WebView, with a FrameLayout. The FrameLayout contains the WebView and an invisible Button (on top). This Button grabs all the touch events. Then, I selectively choose what types of events the WebView should need, and pass them to the WebView. If a touch down and touch up happen close together, with no movement in betweeen, there's no reason for scrolling, so I haven't seen any of that "pixelated" behavior.

由于这是最简单的在这个例子中,我选择了检测MotionEvent.ACTION_UP事件,当它是完整的,我先送下来,这样它模拟一个真实的点击。你可以在ACTION_DOWN肯定触发,但你会得到一个以上的这些,如果用户刷卡或什么的,我想保持这里的逻辑很简单。您可以自定义您认为合适的,而且很可能有足够的工作,即使启用滚动在某些情况下。我希望code以下,就足以传达我的想法的作品。

Because it was simplest for this example, I've chosen to detect the "MotionEvent.ACTION_UP" event, and when it's complete, I send a down first, so that it simulates a real click. You could certainly trigger on ACTION_DOWN, but you'll get more than one of those if the user swipes or something, and I wanted to keep the logic here simple. You can customize as you see fit, and probably with enough work, even enable scrolling in some cases. I hope the code below is enough to relay what I think works.

WebView wv = new WebView(this);
View dummyView = new Button(this);
dummyView.setBackgroundColor(0x00000000);
dummyView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            MotionEvent down = MotionEvent.obtain(100, 100,
                MotionEvent.ACTION_DOWN, event.getX(),
                event.getY(), 0);
            wv.onTouchEvent(down);
            wv.onTouchEvent(event);
        }
        return false;
    }
});
FrameLayout fl = new FrameLayout(this);
fl.addView(wv);
fl.addView(dummyView);
topLayout.addView(fl);

编辑: 如果您不希望编辑PhoneGap的来源,你也许可以做到像下面这样改变PhoneGap的布局......这是未经测试,但好像它应该工作:

If you don't want to edit PhoneGap source, you might be able to do something like the following to change the PhoneGap layout... It's untested, but seems like it should work:

@Override
public void onCreate(Bundle arg0) {
    super.onCreate(arg0);
    super.loadUrl("file:///android_asset/www/index.html");
    // Get the "root" view from PhoneGap
    LinearLayout droidGapRoot = super.root;
    // Create a new "root" that we can use.
    final LinearLayout newRoot = new LinearLayout(this);
    for (int i = 0; i < droidGapRoot.getChildCount(); i++) {
        // Move all views from phoneGap's LinearLayout to ours.
        View moveMe = droidGapRoot.getChildAt(i);
        droidGapRoot.removeView(moveMe);
        newRoot.addView(moveMe);
    }
    // Create an invisible button to overlay all other views, and pass
    // clicks through.
    View dummyView = new Button(this);
    dummyView.setBackgroundColor(0x00000000);
    dummyView.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Only pass "UP" events to the specific view we care about, but
            // be sure to simulate a valid "DOWN" press first, so that the
            // click makes sense.
            if (event.getAction() == MotionEvent.ACTION_UP) {
                MotionEvent down = MotionEvent.obtain(100, 100,
                        MotionEvent.ACTION_DOWN, event.getX(),
                        event.getY(), 0);
                newRoot.onTouchEvent(down);
                newRoot.onTouchEvent(event);
            }
            return false;
        }
    });
    // Layer the views properly
    FrameLayout frameLayout = new FrameLayout(this);
    frameLayout.addView(newRoot);
    frameLayout.addView(dummyView);
    // Add our new customized layout back to the PhoneGap "root" view.
    droidGapRoot.addView(frameLayout);
}

这篇关于图像获取像素化,当屏幕被触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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