How to convert bitmap to byte array in Mono for Android

I am using Mono for Android, I would like to save the bitmap to an array of bytes so I can save it to the database.

Searching here I found the following code snippet:

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

But class "ByteArrayOutputStream" was not found.

Can someone tell me which import space to import that this class contains, or any other way to solve this problem.

Thank you for your time.

+6
source share
2 answers

Instead, you need to use a MemoryStream in MonoDroid. Try the following:

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

import this package import java.io.ByteArrayOutputStream;

0
source

Source: https://habr.com/ru/post/908295/


All Articles