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"& ...
随机推荐
- Maven本地仓库引入自定义/第三方的jar
在cmd下输入如下: mvn install:install-file -Dfile=D:\ojdbc7.jar -DgroupId=com.tech4j.driver -DartifactId=or ...
- Linux 系统/etc/profile 内配置 系统脚本命令
背景 在Linux系统下,我们需要利用脚本命令启动一个进程的时候,需要先找到找到启动文件,然后再启动.比如服务器上安装了一个was应用服务器,我们需要每次启动服务器都需要使用如下命令: sh was ...
- How to Install LibreOffice 6.0 on Ubuntu 16.04 LTS +
1. Add the LibreOffice 6.0 PPA The LibreOffice Fresh PPA is maintained by LibreOffice. It provides l ...
- 分布式事务框架&解决方案参考
两种开源解决方案框架介绍: https://blog.csdn.net/zyndev/article/details/79604395#_97 LCN: https://www.jianshu.com ...
- Python中的open和codecs.open
最近老被编码困扰,多次折腾之后,感觉python的编解码做得挺好的,只要了解下边的流程,一般都能解决 input文件(gbk, utf-8...) ----decode-----> unicod ...
- Get and Set Column/Row Names for Data Frames
row.names(x)row.names(x) <- value rownames(x, do.NULL = TRUE, prefix = "row") rownames( ...
- 集合01_List
List集合总览 元素有序,可重复,可通过索引访问 增加了通过索引操作集合的方法,如: Object get(int index) Object remove(int index) void sort ...
- (转)Awesome Knowledge Distillation
Awesome Knowledge Distillation 2018-07-19 10:38:40 Reference:https://github.com/dkozlov/awesome-kno ...
- Vue.extend提供自定义组件的构造器
Vue.extend 返回的是一个“扩展实例构造器”,也就是预设了部分选项的Vue实例构造器.经常服务于Vue.component用来生成组件,可以简单理解为当在模板中遇到该组件名称作为标签的自定义元 ...
- 【ASP.NET】System.Web.Routing - HttpMethodConstraint Class
你可以自己定义你的ASP.NET程序接收的get post put 或者delete请求. 使用这个约束的方式为: void Application_Start(object sender, Even ...