TextureView getBitmap java.lang.IllegalStateException

时间:2017-07-05 02:25:55

标签: java illegalstateexception ui-thread hardware-acceleration textureview

我通过TextureView启动getBitmap的线程,但是,我得到一个例外:

E/AndroidRuntime: FATAL EXCEPTION: Thread-814
java.lang.IllegalStateException: Hardware acceleration can only be used with a single UI thread.
Original thread: Thread[main,5,main]
Current thread: Thread[Thread-814,5,main]
    at android.view.HardwareRenderer$GlRenderer.checkCurrent(HardwareRenderer.java:1343)
    at android.view.HardwareRenderer$GlRenderer.validate(HardwareRenderer.java:1080)
    at android.view.TextureView.getBitmap(TextureView.java:587)
    at com.example.zmc.colorfultextproject.demo2.SecondActivity.getFrame(SecondActivity.java:153)
    at com.meitu.colorfultext.ColorfulTextView$1.run(ColorfulTextView.java:131)
    at java.lang.Thread.run(Thread.java:856)

在我的代码中

private TextureView demo2VideoTtv;

public Bitmap getFrame() {
    //这里会造成抖动
    long start = System.currentTimeMillis();
    demo2VideoTtv.getBitmap(mFrame); // here throw exception
    Log.d("SecondActivity", "getFrame time" + (System.currentTimeMillis() - start));
    //裁剪图片
    mFrame_part = Bitmap.createBitmap(mFrame, demo2ColorfulText.getLeft(), demo2ColorfulText.getTop(), demo2ColorfulText.getWidth(), demo2ColorfulText.getHeight());
    return mFrame_part;
}

1 个答案:

答案 0 :(得分:0)

我不确定确切的api阈值,但在旧设备上必须在UI线程上请求TextureView.getBitmap()。

它似乎不是21岁以上的问题。最后我看到它在api 19上可以重现。