从Android上的一个BroadcastReceiver处理图像 [英] Processing image from a BroadcastReceiver on Android

查看:121
本文介绍了从Android上的一个BroadcastReceiver处理图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试处理来自Android上一个BroadcastReceiver的形象,但我的日志显示以下错误:没有当前上下文(每个线程记录一次)调用的OpenGL ES API。有任何想法吗。这是我的code:

 公共无效processingImage(字符串图像){            尝试{             如果(形象!= NULL){               BMP = convertBitmap(图片);
               ByteArrayOutputStream流=新ByteArrayOutputStream();
               bmp.com preSS(Bitmap.Com pressFormat.PNG,100,流);
               bitmaps.add(BMP);               的字节数组= stream.toByteArray();
             }
             }赶上(例外五){             }
    }私人位图convertBitmap(字符串图像)抛出MalformedURLException的,IOException异常{
    位图B = BitmapFactory.de codeStream((InputStream的)新的URL(http://mydomain.com/upload/+图片).getContent());
    返回b;
}


解决方案

您不应该做的BroadcastReciever什么比启动服务和活动等。广播接收器通过系统,具有非常有限的上下文中实例当中,很可能因为缺少图形加速支持。

android.graphics 包中包含密切相关的平台中的硬件图形,因此Android Context对象没有实际的OpenGL上下文类不能被用来执行本规定的一些操作包。

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

解决方案

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.

这篇关于从Android上的一个BroadcastReceiver处理图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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