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

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

问题描述

我在 Android 上使用 Mono,我想将位图保存到字节数组所以我可以将它保存到数据库中.

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.

在这里搜索我发现了以下一段代码:

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();

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

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