Bitmap Byte[] 互转
严正声明:
作者:psklf
出处: http://www.cnblogs.com/psklf/p/5889978.html
欢迎转载,但未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任!
Bitmap->byte[]
int bytes = bmp.getByteCount(); ByteBuffer buf = ByteBuffer.allocate(bytes);
bmp.copyPixelsToBuffer(buf); byte[] byteArray = buf.array();
byte[] ->BitMap
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
有人说这个可以实现,来根据ByteArray直接得到bitmap,但是我使用中出现问题。想想其实很简单,就这么一行语句,一个bitmap对象必须的参数都没有设置,怎么就可能得到正常的bitmap对象?这个方法生效的前提是
,提供的bitmapdata是包含了图像参数的,而非简单的RGBA数据。而我现在得到的仅仅是RGBA数据,所以需要先得到一个bitmap实例,再往里填数据。需要将得到的array再变回buffer,使用buffer的 wrap 方法,包装数
组得到buffer.
// use Bitmap.Config.ARGB_8888 instead of type is OK
Bitmap stitchBmp = Bitmap.createBitmap(width, height, type); stitchBmp.copyPixelsFromBuffer(ByteBuffer.wrap(byteArray)); imageView.setImageBitmap(stitchBmp);
参考资料
How do I convert raw camera data into a Bitmap on Android
How to convert byte array to Bitmap
Bitmap Byte[] 互转的更多相关文章
- Bitmap byte[] InputStream Drawable 互转
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStrea ...
- 【转】Drawable /Bitmap、String/InputStream、Bitmap/byte[]
原文:http://wuxiaolong.me/2015/08/10/Drawable-to-Bitmap/ Drawable互转Bitmap Drawable转Bitmap 1234 Resourc ...
- Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 【Android】[转] Android中Bitmap,byte[],Drawable相互转化
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- 字符串string和内存流MemoryStream及比特数组byte[]互转
原文:字符串string和内存流MemoryStream及比特数组byte[]互转 字符串string和内存流MemoryStream及比特数组byte[]互转比较 定义string变量为str, ...
- Android中如何将Bitmap byte裸数据转换成Bitmap图片int数据
Android中如何将Bitmap byte裸数据转换成Bitmap图片int数据 2014-06-11 10:45:14 阅读375次 我们在JNI中处理得到的BMP图片Raw数据,我们应该如何 ...
- Bitmap,byte[],Drawable相互转化
1.Drawable就是一个可画的对象.其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable).还有可能是一个图层(LayerDrawable),我们依据绘图 ...
- Go语言网络通信---string与int互转,int64与[]byte互转,int直接互转,string与[]byte互转
string与int互转 #string到int int,err:=strconv.Atoi(string) #string到int64 int64, err := strconv.ParseInt( ...
- byte,bitmap,image互转
/// <summary> /// 将图片Image转换成Byte[] /// </summary> /// <param name="Image"& ...
随机推荐
- Windows Installation
If you're running on Windows it is good to run Jenkins as a service so it starts up automatically wi ...
- topcoder srm 400 div1
problem1 link 枚举指数,然后判断是不是素数即可. problem2 link 令$f[len][a][b][r]$(r=0或者1)表示子串$init[a,a+len-1]$匹配$goal ...
- Delphi XE5 for Android (九)
Delphi XE5 下TEdit控件有个属性:KeyboardType,如下图: 该属性决定了当焦点进入TEdit时,系统弹出的输入窗体,按照其帮助文件说明,不同取值的输入窗体不同,如下图: 根 ...
- Bootstrap3基础 container 浏览器宽度与容器宽度的四种配合
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- SpringBoot 使用Druid连接池
1.pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- 【原理、应用】Quartz集群原理及配置应用
一.Quartz任务调度的基本实现原理 Quartz是OpenSymphony开源组织在任务调度领域的一个开源项目,完全基于Java实现.作为一个优秀的开源调度框架,Quartz具有以下特点: 强大的 ...
- watch监控,对比新值和旧值做出相应判断
数据变化的监控经常使用,我们可以先来看一个简单的数据变化监控的例子.例如天气预报的穿衣指数,它主要是根据温度来进行提示的,当然还有其它的,咱们就不考虑了. html <div id=" ...
- 3D场景鼠标点选择物体
对于以下几种选择: (1)点云: (2)线框: (3)网格: 针对以上准备三个函数: (1)获取点和线段最短距离函数: (2)获取线段和线段最短距离函数: (3)获取三角面片和线段最短距离函数: 算法 ...
- Linux下 网卡测速
参考: How do I verify the speed of my NIC? Linux下 网卡测速 命令: $ sudo ethtool eth0 Settings for eth0: Supp ...
- 18. --plic--=--ply--=--pli--=--ple--=--plex--=--plo-- to fold 倍,重,折叠 (词19、20)
词汇速记20