Processing image from a BroadcastReceiver on Android

可紊 提交于 2020-01-06 08:25:12

问题


I´m trying to process an image from a BroadcastReceiver on Android but my log display the following error: call to OpenGL ES API with no current context (logged once per thread). Any ideas. this is my code:

 public void processingImage(String image){

            try {

             if(image != null){

               bmp = convertBitmap(image);
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
               bitmaps.add(bmp);

               byteArray = stream.toByteArray(); 
             } 


             } catch (Exception e) {

             }
    }

private Bitmap convertBitmap(String image) throws MalformedURLException, IOException{


    Bitmap b = BitmapFactory.decodeStream((InputStream)new URL("http://mydomain.com/upload/" +  image ).getContent());
    return b;
}

回答1:


You shouldn't do anything in BroadcastReciever other than starting services and activities. BroadcastReceiver instantiated by system with a very limited context which, probably, lacks accelerated graphics support.

android.graphics package contains classes that tightly related to graphic hardware in platform, so Android Context object without actual openGL context can not be used to perform some manipulations specified in this package.



来源:https://stackoverflow.com/questions/21996899/processing-image-from-a-broadcastreceiver-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!