实习入职第十二天:Android中Bitmap,byte[],Drawable,InputStream相互转化工具类

玩转Zabbix智能告警:降噪、排班、认领、升级、IM协同 集成Zabbix告警到FlashDuty,获得告警降噪、智能排班、IM协同等能力 阅读详情
1、将byte[]转换成InputStream  
    public InputStream Byte2InputStream(byte[] b) {  
        ByteArrayInputStream bais = new ByteArrayInputStream(b);  
        return bais;  
    }  
  
2、 将InputStream转换成byte[]  
两种方式:
一、
 public static final byte[] InputStream2Bytes(InputStream inStream) {
    ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
    byte[] buff = new byte[100];
    int rc = 0;
    try {
  while ((rc = inStream.read(buff, 0, 100)) > 0) {
  swapStream.write(buff, 0, rc);
  }
  } catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
    byte[] in2b = swapStream.toByteArray();
    return in2b;
    }
二、
    public byte[] InputStream2Bytes(InputStream is) {  
        String str = "";  
        byte[] readByte = new byte[1024];  
        int readCount = -1;  
        try {  
            while ((readCount = is.read(readByte, 0, 1024)) != -1) {  
                str += new String(readByte).trim();  
            }  
            return str.getBytes();  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return null;  
    }  
  

3、 将Bitmap转换成InputStream  
    public InputStream Bitmap2InputStream(Bitmap bm, int quality) {  
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        bm.compress(Bitmap.CompressFormat.PNG, quality, baos);  
        InputStream is = new ByteArrayInputStream(baos.toByteArray());  
        return is;  
    }  
  
4、 将InputStream转换成Bitmap  
    public Bitmap InputStream2Bitmap(InputStream is) {  
        return BitmapFactory.decodeStream(is);  
    }  
  
5、 Drawable转换成InputStream  
    public InputStream Drawable2InputStream(Drawable d) {  
        Bitmap bitmap = this.drawable2Bitmap(d);  
        return this.Bitmap2InputStream(bitmap);  
    }  
  
6、 InputStream转换成Drawable  
    public Drawable InputStream2Drawable(InputStream is) {  
        Bitmap bitmap = this.InputStream2Bitmap(is);  
        return this.bitmap2Drawable(bitmap);  
    }  
  
7、 Drawable转换成byte[]  
    public byte[] Drawable2Bytes(Drawable d) {  
        Bitmap bitmap = this.drawable2Bitmap(d);  
        return this.Bitmap2Bytes(bitmap);  
    }  
8、 byte[]转换成Drawable  
    public Drawable Bytes2Drawable(byte[] b) {  
        Bitmap bitmap = this.Bytes2Bitmap(b);  
        return this.bitmap2Drawable(bitmap);  
    }  
  
8、 Bitmap转换成byte[]  
    public byte[] Bitmap2Bytes(Bitmap bm) {  
        ByteArrayOutputStream baos = new ByteArrayOutputStream();  
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);  
        return baos.toByteArray();  
    }  
  
9、 byte[]转换成Bitmap  
    public Bitmap Bytes2Bitmap(byte[] b) {  
        if (b.length != 0) {  
            return BitmapFactory.decodeByteArray(b, 0, b.length);  
        }  
        return null;  
    }  
  
10、Drawable转换成Bitmap  
    public Bitmap drawable2Bitmap(Drawable drawable) {  
        Bitmap bitmap = Bitmap  
                .createBitmap(  
                        drawable.getIntrinsicWidth(),  
                        drawable.getIntrinsicHeight(),  
                        drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888  
                                : Bitmap.Config.RGB_565);  
        Canvas canvas = new Canvas(bitmap);  
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),  
                drawable.getIntrinsicHeight());  
        drawable.draw(canvas);  
        return bitmap;  
    }  
  
11、 Bitmap转换成Drawable  
    public Drawable bitmap2Drawable(Bitmap bitmap) {  
        BitmapDrawable bd = new BitmapDrawable(bitmap);  
        Drawable d = (Drawable) bd;  
        return d;  
    } 
【TM1650】STM8S TM1650芯片控制程序 以下为.h文件: #ifndef __TM1650_I2C_H #define __TM1650_I2C_H #include "stm8s.h" #include "stm8s_gpio.h" #include "tim1.h" #include "usart2.h" #include <iostm8s103f3.h> #include <intrinsics.... 阅读详情

相关推荐

静态时序分析(Static Timing Analysis, STA):简介及内容导航

静态时序分析(简称STA)是用来验证数字设计时序的技术之一,另外一种验证时序的方法是时序仿真,时序仿真可以同时验证功能和时序。“时序分析”这个术语就是用来指代“静态时序分析“或”时序仿真“这两种方法之一,简单来说,时序分析的目的就是为了解决设计中的各种时序问题。STA被称为静态的原因是其对于设计的分析是静态地执行的,并不依赖于施加在输入端口上的激励。相比之下,时序仿真则可以被视作动态地执行对设计的分析,具体过程描述如下:施加一组激励,观察在这组激励下电路行为是否符合要求,然后换一组激。

Starry__的博客 2033

Android中Bitmap,byte[],Drawable,InputStream相互转化工具类

http://blog.sina.com.cn/s/blog_7dbac1250101nps0.html 1、将byte[]转换成InputStream       public InputStream Byte2InputStream(byte[] b) {           ByteArrayInputStream bais = new ByteArrayInp

mengzhengjie的专栏 647

低代码Agent开发框架使用指南(二)—Coze平台核心功能概览

本篇分享系统介绍了字节跳动推出的低代码智能体开发平台Coze。Coze以免费易用、多模型支持和便捷的跨平台发布为核心优势,显著降低了智能体开发门槛。文章详细解析了平台的六大核心功能:扩展能力边界的插件系统、增强认知的知识库、结构化数据管理的数据库、可视化图像处理的图像流、实现复杂逻辑编排的工作流,以及处理复杂任务的多智能体协作机制,全面展现了Coze平台的强大能力。

weixin_42782643的博客 1368

android BitMap、Drawable、inputStream及byte[] 互转

1. Bitmap转换为inputStream ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); InputStream isBm = new ByteArrayInputStream(baos .toByteArray()); 2. BitMap转换为byte[] Bitmap bitmap = Bitma

圆静居士的专栏 720

PINN for PDE(偏微分方程)4 - 反向问题 - Burgers’ equation

PINN for PDE(偏微分方程)4 - 反向问题 - Burgers’ equation

m0_62030579的博客 3029

Zynq实战:如何用AXI4-Stream To Video Out实现HDMI视频输出(附时序调试技巧)

本文详细介绍了基于Zynq平台使用AXI4-Stream To Video Out IP核实现HDMI视频输出的工程化解决方案。内容涵盖系统架构设计、AXI4-Stream接口优化、异步FIFO配置、时序同步调试技巧等核心环节,特别针对1080p60视频输出提供具体参数配置和性能优化建议,帮助开发者快速构建稳定的视频处理系统。

sql99的博客 470

Android中InputStream与String,Byte之间互转

我们大家在学习Android的时候,客户端进行Http请求的时候一般通过HttpsURLConnection.getInputStream()来获得一个Inputstream, 一般我们需要将这个流转换的成String,查了API后发现Inputstream没有转换成String的方法,一次我们需要自己写方法来转换。 本文通过代码的方式来写出InputStream与String,Byte之间互

hj11030603的专栏 1738

Qwen3.6-27B本地部署实战:LM Studio配置、硬件门槛与避坑指南

大语言模型本地部署是当前AI工程落地的核心能力之一,其本质是将高参数量模型(如27B级)在受限硬件环境下实现低延迟、高稳定推理。关键技术原理涵盖量化压缩(如GGUF格式与q4_k_m精度权衡)、GPU显存分配策略(KV Cache管理与Offloading机制)、以及运行时环境兼容性(CUDA驱动、llama.cpp后端版本)。该能力直接决定私有化AI应用的技术可行性与成本边界,广泛应用于企业知识库构建、代码辅助、长文档分析等对数据主权和响应确定性要求高的场景。本文聚焦Qwen3.6-27B这一典型27B模

weixin_33272631的博客 481

InputStream与String,Byte之间互转

import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; /** * * @author Andy.Chen * @mail Chenju

zhoujiyu123的专栏 661

6、Cocos2D游戏开发:精灵添加与角色实现

本文详细介绍了在Cocos2D游戏开发中如何添加背景精灵和玩家角色精灵。通过创建GameScene场景、组织项目资源、使用多分辨率图像适配不同设备,并深入讲解了将角色拆分为上下半身以实现更真实瞄准效果的原理。文章还解析了Cocos2D的图像搜索机制、锚点概念及其应用,以及如何通过父子节点关系管理复合角色。最终实现了猎人角色在场景中的正确显示与定位,为后续动画和交互功能打下基础。

e3f4g5的博客 105

Android开发工程师(IOT)面试指南与参考答案

【摘要】绿联科技招聘Android开发工程师(IOT方向),要求5年以上Android开发经验,精通Kotlin/Java,熟悉IOT设备交互及跨平台开发。岗位职责包括客户端开发维护、技术调研及性能优化等。核心考察点包括:Kotlin协程在IOT低功耗场景的应用、多协议设备连接层设计、音视频性能优化及离线架构实现。重点技术涉及蓝牙Mesh群控、BLE功耗优化及ReactNative混合开发。需具备GooglePlay合规经验,熟悉Android13+权限管理,并能提供量化性能优化案例。

郑伟强dev的专栏 733

android InputStream 转byte[]

public static byte[] streamToBytes(InputStream input) { ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int n = 0; try { while (-1 != (n = input.read(buffer))) { ...

weixin_35861115的博客 971

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import android.graphics.Bitmap; import android.graphics.BitmapFactory;

肖赛SoAi 3万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Android Bitmap Drawable byte[] InputStream 相互转换方法

用android处理图片的时候,由于得到的资源不一样,所以经常要在各种格式中相互转化,以下介绍了 Bitmap Drawable byte[] InputStream 之间的转换方法: import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Inp...

diaobo9395的博客 217

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Bitmap与DrawAble与byte[]与InputStream之间的转换工具类

整合网络上一些针对Bitmap和DrawAble的工具使用类 import java.io.ByteArrayInputStream;   import java.io.ByteArrayOutputStream;   import java.io.InputStream;      import android.graphics.Bitmap;   import androi

RickyStudio的专栏 722

android inputstream转bitmap,android Bitmap与Drawable与byte[]与InputStream之间的转换工具类...

package com.shntec.xmm.platform;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.InputStream;import android.graphics.Bitmap;import android.graphics.BitmapFactory...

weixin_31046701的博客 504

Android之Drawable转换drawable、bitmap、byte[]

在代码中我们有时需要获取res下的资源文件,尤其是Drawable的图片文件并转换bitmap,或者相互转换Drawable  转  Bitmap方法一:Drawable drawable = getResources().getDrawable(R.drawable.icon); imageview.setBackground(drawable);方法二:Inputstream is = get...

丿CoolTone的博客 1284

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[]: Bitm...

bobo的博客 315

android inputstream转bitmap,Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】...

packagecom.soai.imdemo;importjava.io.ByteArrayInputStream;importjava.io.ByteArrayOutputStream;importjava.io.InputStream;importandroid.graphics.Bitmap;importandroid.graphics.BitmapFactory;importandroid...

weixin_30647853的博客 465

android outputstream转bitmap,android Bitmap与Drawable与byte[]与InputStream之间的转换工具类...

package com.shntec.xmm.platform;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.InputStream;import android.graphics.Bitmap;import android.graphics.BitmapFactory...

weixin_35834213的博客 509

android bitmap的各种转化

package com.FJlijinyi.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import android.graphics.Bitmap; import android.grap...

FJlijinyi的博客 425
上一篇: 实习入职第十二天:MediaPlayer时间之间的转换函数
下一篇: 实习入职第十三天:MediaPlayer的seekTo函数
wust小吴
博客等级 码龄13年 190粉丝 284原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值