1、图片byte数据转Bitmap

使用Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath())容易导致内存溢出。

public static Bitmap decodeImg(byte[] imgByte) {        Bitmap bitmap = null;        InputStream input = null;        try {            BitmapFactory.Options options = new BitmapFactory.Options();            options.inSampleSize = 8;            input = new ByteArrayInputStream(imgByte);            SoftReference softRef = new SoftReference(BitmapFactory.decodeStream(input, null, options));            bitmap = (Bitmap) softRef.get();        } catch (Exception e) {            e.printStackTrace();        } finally {            if (imgByte != null) {                imgByte = null;            }            if (input != null) {                try {                    input.close();                } catch (IOException e) {                    e.printStackTrace();                }            }        }        return bitmap;    }

2、使用Timer+TimerTask+Handler实现定时器

public class HanderDemoActivity extends Activity {      TextView tvShow;      private int i = 0;      private int TIME = 1000;        @Override      public void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.main);          tvShow = (TextView) findViewById(R.id.tv_show);          timer.schedule(task, 1000, 1000); // 1s后执行task,经过1s再次执行      }        Handler handler = new Handler() {          public void handleMessage(Message msg) {              if (msg.what == 1) {                  tvShow.setText(Integer.toString(i++));              }              super.handleMessage(msg);          };      };      Timer timer = new Timer();      TimerTask task = new TimerTask() {            @Override          public void run() {              // 需要做的事:发送消息              Message message = new Message();              message.what = 1;              handler.sendMessage(message);          }      };  }  


更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. android 使用html5作布局文件: webview跟javascript交互
  6. android实现字体闪烁动画的方法
  7. Android(安卓)Resource介绍和使用
  8. "Failed to fetch URL https://dl-ssl.google.com/android/repos
  9. 使用NetBeans搭建Android开发环境

随机推荐

  1. Android 官方示例:android-architecture
  2. Android ADT_20新建项目Android Support
  3. Android系统架构及特点
  4. Android Material Design向下兼容至低版
  5. 在EeePC上运行Android!(转)(也是代码下载配
  6. Android利用drawable文件夹自定义控件背
  7. Android(安卓)Audio底层原理(一)
  8. android环境配置(Error generating final
  9. android上dialog横屏下实现全屏效果
  10. Android EditText自动获取焦点并弹出软键