0

Je commence un fil à GetBitmap par TextureView, cependant, je reçois une exception:TextureView GetBitmap java.lang.IllegalStateException

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) 

dans mon code

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

Répondre

0

Je ne suis pas sûr de la seuil d'api exact mais sur les périphériques plus anciens TextureView.getBitmap() doit être demandé sur le thread d'interface utilisateur.

Cela ne semble pas être un problème sur 21+. J'ai vu qu'il était reproductible sur l'api 19.