zoukankan      html  css  js  c++  java
  • BitMap、Drawable、inputStream及byte[] 互转

    (1) BitMap to inputStream:
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
    InputStream isBm = new ByteArrayInputStream(baos .toByteArray());

    (2)BitMap to byte[]:
    Bitmap defaultIcon = BitmapFactory.decodeStream(in);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitmapdata = stream.toByteArray();
    (3)Drawable to byte[]:
    Drawable d; // the drawable (Captain Obvious, to the rescue!!!)
    Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, bitmap);
    byte[] bitmapdata = stream.toByteArray();

    (4)byte[] to Bitmap :
    Bitmap bitmap =BitmapFactory.decodeByteArray(byte[], 0,byte[].length);

    看不清未来,就做好现在,,,
  • 相关阅读:
    Thread Based Parallelism
    Thread Based Parallelism
    The Divide and Conquer Approach
    Algorithms
    FTP
    POP and IMAP
    通过 python 处理 email
    Android开发环境搭建简介
    Hello world
    mybatis3.2初学感悟
  • 原文地址:https://www.cnblogs.com/gsdimz/p/3088756.html
Copyright © 2011-2022 走看看