zoukankan      html  css  js  c++  java
  • Android为TV端助力 bitmap和数据流的互转

    Bitmap aa = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    InputStream input = datastream(aa);//把bitmap转换为流
    Bitmap bitmap = transformation(input);//把流转换为bitmap

    public InputStream datastream (Bitmap bm){
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
    ByteArrayInputStream is = new ByteArrayInputStream(stream.toByteArray());
    return is;
    }

    public Bitmap transformation(InputStream input){
    if(input != null){
    int len =-1;
    byte[] temp = new byte[4 * 1024];
    ByteArrayBuffer buffer = new ByteArrayBuffer(2 * 1024 * 1024);
    try {
    while ((len = input.read(temp)) != -1) {
    buffer.append(temp,0,len);
    }
    Bitmap bmp = BitmapFactory.decodeByteArray(buffer.buffer(), 0, buffer.length());//把流转换为bitmap
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    return bmp;
    }

  • 相关阅读:
    POJ2253Frogger
    POJ3982The Fibonacci sequence
    POJ3259Wormholes
    POJ1062Expensive dowry
    POJ1860Currency Exchange
    POJ1789Truck History .
    POJ2602Superlong sums
    POJ1125Stockbroker Grapevine
    POJ2485Highways
    POJ2240Arbitrage
  • 原文地址:https://www.cnblogs.com/xiaoxiaing/p/5534998.html
Copyright © 2011-2022 走看看