如何转换位图字节数组中的单声道为Android [英] How to convert bitmap to byte array in Mono For Android

查看:102
本文介绍了如何转换位图字节数组中的单声道为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用单声道为Android,我想一个位图保存到一个字节数组 因此,我可以将它保存到数据库中。

I am using Mono for Android, I would like to save a bitmap to a byte array  So I can save it to a database.

搜索在这里我找到了下面这段code:

Searching in here I found the following piece of code:

ByteArrayOutputStream bos = new ByteArrayOutputStream();  
bitmap.compress(CompressFormat.PNG, 0, bos);  
byte[] bitmapdata = bos.toByteArray();  

但ByteArrayOutputStream类未找到。

But  the "ByteArrayOutputStream"  class is not found.

有人可以告诉我什么命名空间导入包含该类或来解决这个问题的任何其他方式。

Can somebody tell me what namespace to import that contains this class or any other way to solve this problem. 

感谢您的时间。

推荐答案

您需要在MonoDroid使用的MemoryStream代替。 试试这个:

You need to use MemoryStream in MonoDroid instead. Try this:

MemoryStream stream = new MemoryStream();
bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
byte[] bitmapData = stream.ToArray();

这篇关于如何转换位图字节数组中的单声道为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆